-
Notifications
You must be signed in to change notification settings - Fork 0
/
3__Loops and Strings.js
112 lines (78 loc) · 1.69 KB
/
3__Loops and Strings.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// for Loop
for (let i = 1; i <= 5; i++) {
console.log("Shoeb");
// for (let i = 1; i <= 5; i++) {
// console.log("Shoeb");
let sum = 0 ;
for (let i = 1; i <= 5; i++) {
sum = sum + i;
}
console.log(sum);
console.log('loop done')
let sum = 0 ;
for (let i = 1; i <= 5; i--) {
sum = sum - i;
}
// While Loop
let i = 1;
while(i <= 5) {
console. log("i=", i);
i++;
}
// do while loop
let i = 20;
do {
console. log("Prine only one");
i++;
} while (i <= 10);
let i = 20;
do {
console. log("Prine only one");
i--;
} while (i <= 10);
// do while didt use for personal case
// array
// practies for loop
//Practice Qs1
for(let num=0; num <= 100; num++){
console. log ("num =", num) ;
}
//Practice Qs2 even number and odd number
for(let num=0; num <= 100; num++){
if (num %2 === 0){
console.log("num=", num);
}
}
for(let num=0; num <= 100; num++){
if (num %2 === 1){
console.log("num=", num);
}
}
let gameNum = 25;
let userNum = prompt("Guess the game number : ");
while(userNum != gameNum) {
let userNum = prompt("You enter wrong number, Guess again : ");
}
console.log("congo You enter the right Number");
let obj = {
item: "pen",
price: 10,
};
let output = `the cost of ${obj. item} is ${obj.price} rupees`;
console.log(output);
// console.log("the cost of", obj.item, "is", obj.price, "rupees");
// Template Literals
let specialString = 'This is a template literal ${1 + 2 +3}';
console. log (specialString);
// escafe char
next line /n
tab /t
let str = "01234546";
console.log(str.slice(1, 3));
let str1 = "SHOEB";
let str2 = "SIkder";
let res = str2.concat(str2);
console. log (res);
let res = str1.concat(str1);
console. log (res);
// ffor new code