@@ -5,267 +5,249 @@ let num2 = 8;
5
5
console . log ( "I am the regular upper code" ) ;
6
6
7
7
if ( num1 > num2 ) {
8
- console . log ( "num 1 is greater than num2" ) ;
8
+ console . log ( "num 1 is greater than num2" ) ;
9
9
} else {
10
- console . log ( "num 1 is not greater than num2" ) ;
10
+ console . log ( "num 1 is not greater than num2" ) ;
11
11
}
12
12
13
13
console . log ( "I am regular bottom code" ) ;
14
14
15
-
16
15
// Checking if a string is equal to another string:
17
16
18
17
let username = "chai" ;
19
18
let anotherUsername = "chai" ;
20
19
21
20
if ( username != anotherUsername ) {
22
- console . log ( "Pick another username" ) ;
21
+ console . log ( "Pick another username" ) ;
23
22
} else {
24
- console . log ( "Didn't get any username" ) ;
23
+ console . log ( "Didn't get any username" ) ;
25
24
}
26
25
27
-
28
-
29
26
// Checking if a variable is the number or not:
30
27
31
28
let score = 44 ;
32
29
33
- if ( typeof ( score ) === ' number' ) {
34
- console . log ( "Yep, this is the number" ) ;
30
+ if ( typeof score === " number" ) {
31
+ console . log ( "Yep, this is the number" ) ;
35
32
} else {
36
- console . log ( "No that is not a number" ) ;
33
+ console . log ( "No that is not a number" ) ;
37
34
}
38
35
39
36
let arr = [ ] ;
40
37
41
- if ( typeof ( arr ) === ' object' ) {
42
- console . log ( "Yep, this is the object" ) ;
38
+ if ( typeof arr === " object" ) {
39
+ console . log ( "Yep, this is the object" ) ;
43
40
} else {
44
- console . log ( "This is array" ) ;
41
+ console . log ( "This is array" ) ;
45
42
}
46
43
47
-
48
44
// Checking if a boolean value is true or false:
49
45
50
46
let isTeaReady = false ;
51
47
52
48
if ( isTeaReady ) {
53
- console . log ( "Tea is Ready" ) ;
49
+ console . log ( "Tea is Ready" ) ;
54
50
} else {
55
- console . log ( "Tea is not ready !" ) ;
51
+ console . log ( "Tea is not ready !" ) ;
56
52
}
57
53
58
-
59
54
// Check if an array is empty or not:
60
55
61
56
let items = [ ] ;
62
57
63
58
console . log ( items . length ) ;
64
59
65
60
if ( items . length === 0 ) {
66
- console . log ( "Array is empty" ) ;
61
+ console . log ( "Array is empty" ) ;
67
62
} else {
68
- console . log ( "Array is not empty" ) ;
63
+ console . log ( "Array is not empty" ) ;
69
64
}
70
65
71
-
72
66
// INFO: Switch & Case
73
67
const dayNumber = 5 ;
74
68
75
69
switch ( dayNumber ) {
76
- case 0 :
77
- console . log ( "It is sunday Today" ) ;
78
- case 1 :
79
- console . log ( "It is Monday Today.." ) ;
80
- case 2 :
81
- console . log ( "It is Tuesday Today..." ) ;
82
- case 3 :
83
- console . log ( "It is Wednesday Today.." ) ;
84
- case 4 :
85
- console . log ( "It is Thursday Today.." ) ;
86
- case 5 :
87
- console . log ( "It is Friday Today." ) ;
88
- break ;
89
- case 6 :
90
- console . log ( "It is Saturday Today" ) ;
91
- default :
92
- console . log ( "No days left" ) ;
70
+ case 0 :
71
+ console . log ( "It is sunday Today" ) ;
72
+ case 1 :
73
+ console . log ( "It is Monday Today.." ) ;
74
+ case 2 :
75
+ console . log ( "It is Tuesday Today..." ) ;
76
+ case 3 :
77
+ console . log ( "It is Wednesday Today.." ) ;
78
+ case 4 :
79
+ console . log ( "It is Thursday Today.." ) ;
80
+ case 5 :
81
+ console . log ( "It is Friday Today." ) ;
82
+ break ;
83
+ case 6 :
84
+ console . log ( "It is Saturday Today" ) ;
85
+ default :
86
+ console . log ( "No days left" ) ;
93
87
}
94
88
95
89
// INFO: Ternary Operator
96
90
dayNumber == 0 ? console . log ( "It is true..." ) : console . log ( "It is false..." ) ;
97
91
98
92
const gender = "F" ;
99
- const userMessage = `${ gender === "F" ? "She" : "He" } is a college student.`
93
+ const userMessage = `${ gender === "F" ? "She" : "He" } is a college student.` ;
100
94
console . log ( userMessage ) ;
101
95
102
-
103
-
104
96
// INFO: If and else statements
105
97
let age = 20 ;
106
98
if ( age >= 20 ) {
107
- console . log ( "You are an adult..." ) ;
99
+ console . log ( "You are an adult..." ) ;
108
100
} else if ( age >= 13 ) {
109
- console . log ( "You are a teenager..." ) ;
101
+ console . log ( "You are a teenager..." ) ;
110
102
} else {
111
- console . log ( "You are a child..." ) ;
103
+ console . log ( "You are a child..." ) ;
112
104
}
113
105
114
-
115
106
// INFO: Switch Case Statements
116
107
let day = "Monday" ;
117
108
switch ( day ) {
118
- case "Monday" :
119
- console . log ( "Start of the workweek." ) ;
120
- break ;
121
- case "Friday" :
122
- console . log ( "Almost the weekend!" ) ;
123
- break ;
124
- case "Saturday" :
125
- case "Sunday" :
126
- console . log ( "It's the weekend!" ) ;
127
- break ;
128
- default :
129
- console . log ( "It's a regular day." ) ;
109
+ case "Monday" :
110
+ console . log ( "Start of the workweek." ) ;
111
+ break ;
112
+ case "Friday" :
113
+ console . log ( "Almost the weekend!" ) ;
114
+ break ;
115
+ case "Saturday" :
116
+ case "Sunday" :
117
+ console . log ( "It's the weekend!" ) ;
118
+ break ;
119
+ default :
120
+ console . log ( "It's a regular day." ) ;
130
121
}
131
122
132
-
133
123
// INFO: Loops
134
124
// for loop
135
125
for ( let i = 0 ; i < 5 ; i ++ ) {
136
- console . log ( i ) ;
126
+ console . log ( i ) ;
137
127
}
138
128
139
129
// while loop
140
130
let i = 0 ;
141
131
while ( i < 5 ) {
142
- console . log ( i ) ;
143
- i ++ ;
132
+ console . log ( i ) ;
133
+ i ++ ;
144
134
}
145
135
146
136
// Do while loop
147
137
let a = 0 ;
148
138
do {
149
- console . log ( a ) ;
150
- i ++ ;
139
+ console . log ( a ) ;
140
+ i ++ ;
151
141
} while ( i < 5 ) ;
152
142
153
-
154
143
// for of
155
144
const fruits = [ "Apple" , "Banana" , "Cherry" ] ;
156
145
for ( const fruit of fruits ) {
157
- console . log ( fruit ) ;
146
+ console . log ( fruit ) ;
158
147
}
159
148
160
-
161
149
// for-in
162
150
const person = { name : "Alice" , age : 25 } ;
163
151
for ( const key in person ) {
164
- console . log ( key + ": " + person [ key ] ) ;
152
+ console . log ( key + ": " + person [ key ] ) ;
165
153
}
166
154
167
-
168
155
// INFO: Break and continue
169
156
for ( let i = 0 ; i < 5 ; i ++ ) {
170
- if ( i === 3 ) break ;
171
- console . log ( i ) ;
157
+ if ( i === 3 ) break ;
158
+ console . log ( i ) ;
172
159
} // 0 1 2 break will exists the loop;
173
160
174
-
175
161
for ( let i = 0 ; i < 5 ; i ++ ) {
176
- if ( i === 3 ) continue ;
177
- console . log ( i ) ;
162
+ if ( i === 3 ) continue ;
163
+ console . log ( i ) ;
178
164
} // 0 1 2 4 continue skips the current iteration
179
165
180
-
181
166
// NOTE: Quizes
182
167
183
168
// INFO: Quiz 1
184
169
let x = 5 ;
185
- if ( x = 10 ) {
186
- console . log ( "x is 10" ) ;
170
+ if ( ( x = 10 ) ) {
171
+ console . log ( "x is 10" ) ;
187
172
} else {
188
- console . log ( "x is not 10" ) ;
173
+ console . log ( "x is not 10" ) ;
189
174
} // x is 10
190
175
191
176
// INFO: Quiz 2
192
177
const numbers = [ 1 , 2 , 3 , 4 , 5 ] ;
193
178
for ( let i in numbers ) {
194
- if ( i == 2 ) break ;
195
- console . log ( i ) ;
179
+ if ( i == 2 ) break ;
180
+ console . log ( i ) ;
196
181
} // 0 1
197
182
198
-
199
183
// INFO: Quiz 3
200
184
let z = 0 ;
201
185
while ( z < 3 ) {
202
- console . log ( z ) ;
203
- z ++ ;
186
+ console . log ( z ) ;
187
+ z ++ ;
204
188
} // 0 1 2
205
189
206
190
// INFO: Quiz 4
207
191
let count = 0 ;
208
192
do {
209
- console . log ( count ) ;
210
- count ++ ;
193
+ console . log ( count ) ;
194
+ count ++ ;
211
195
} while ( count < 0 ) ; // 0
212
196
213
197
// INFO: Quiz 5
214
198
let value = 0 ;
215
199
for ( let i = 0 ; i < 5 ; i ++ ) {
216
- if ( i % 2 === 0 ) continue ;
217
- value += i ;
200
+ if ( i % 2 === 0 ) continue ;
201
+ value += i ;
218
202
}
219
203
console . log ( value ) ; // 4
220
204
221
205
// INFO: Quiz 6
222
206
let output = "" ;
223
207
switch ( "apple" ) {
224
- case "banana" :
225
- output += "Banana " ;
226
- case "apple" :
227
- output += "Apple " ;
228
- case "orange" :
229
- output += "Orange " ;
230
- break ;
231
- default :
232
- output += "None" ;
208
+ case "banana" :
209
+ output += "Banana " ;
210
+ case "apple" :
211
+ output += "Apple " ;
212
+ case "orange" :
213
+ output += "Orange " ;
214
+ break ;
215
+ default :
216
+ output += "None" ;
233
217
}
234
218
console . log ( output ) ; // banana orange
235
219
236
220
// INFO: Quiz 7
237
221
for ( let i = 0 ; i < 3 ; i ++ ) {
238
- for ( let j = 0 ; j < 2 ; j ++ ) {
239
- if ( j === 1 ) break ;
240
- console . log ( i , j ) ;
241
- }
222
+ for ( let j = 0 ; j < 2 ; j ++ ) {
223
+ if ( j === 1 ) break ;
224
+ console . log ( i , j ) ;
225
+ }
242
226
} // 0 0, 1 0, 2 0
243
227
244
228
// INFO: Quiz 8
245
229
let c = 0 ;
246
230
while ( c < 3 ) {
247
- if ( c === 1 ) continue ;
248
- console . log ( c ) ;
249
- c ++ ;
231
+ if ( c === 1 ) continue ;
232
+ console . log ( c ) ;
233
+ c ++ ;
250
234
} // 0 2
251
235
252
236
// INFO: Quiz 9
253
237
let count1 = 0 ;
254
238
do {
255
- console . log ( ) ;
256
- count1 ++ ;
257
- if ( count1 === 2 ) break ;
239
+ console . log ( ) ;
240
+ count1 ++ ;
241
+ if ( count1 === 2 ) break ;
258
242
} while ( count1 < 5 ) ; // 0 1
259
243
260
244
// INFO: Quiz 10
261
245
let result = 0 ;
262
246
for ( let i = 1 ; i <= 5 ; i ++ ) {
263
- if ( i % 2 === 0 ) {
264
- result += i ;
265
- } else {
266
- result -= i ;
267
- }
247
+ if ( i % 2 === 0 ) {
248
+ result += i ;
249
+ } else {
250
+ result -= i ;
251
+ }
268
252
}
269
253
console . log ( result ) ; // 5
270
-
271
-
0 commit comments