-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththird.js
More file actions
70 lines (52 loc) · 1.59 KB
/
third.js
File metadata and controls
70 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// /*Topic : Lops and Strings*/
let str = "Suraj";
// //1. while loop
let sum = 0;
let i = 1;
while(i<=10){
sum = sum + i;
i++;
}
console.log(sum);
// //2. do...while loop
let numberOfTimesPrinting = Number.parseInt(prompt("Enter the number of time to print 'Suraj' :"));
let j = 1;
do{
console.log("Suraj" + " ");
j++;
}while(j<=numberOfTimesPrinting);
// //3.for loop
const car = ['Volvo' , 'BMW', 'Lambo' , 'Mercedis']; //declaration 1
const person = new Array("Suraj" , "Ashikh" , "Vyanakatesh" ,"Chinmay"); //declaration 2
const car2 = ['Volvo' , 'BMW', 'Lambo' , 'Mercedis'];
for(let i = 0 ; i < car.length ; i++){
console.log(car[i] + " ");
}
for(let k in person){ //for in
console.log(person[k]);
}
for(let x of car2){ //for of
console.log(x);
}
//4 . Strings methods
let str1 = "Suraj";
let str2 = new String("Ashikh");
console.log((str1 == str2)? true : false);
console.log(str1.length);
console.log(str1.toUpperCase());
console.log(str1.toLowerCase());
console.log(str1.charCodeAt(0));
console.log(str1.charAt(1));
console.log(str1[0].toUpperCase());
let text = "Apple, Banana, Kiwi";
console.log(text.slice(7, 13));
console.log(text.substr(7));
console.log(text.substring(7, 13));
console.log(text.substring(7, 13));
let str3 = str1.concat(" " , str2 ," are friends");
console.log(str3);
let result = str1.repeat(5);
console.log(result);
let text2 = "Please visit Microsoft!";
let newText = text2.replace("Microsoft", "W3Schools");
console.log(newText);