@@ -5,267 +5,249 @@ let num2 = 8;
55console . log ( "I am the regular upper code" ) ;
66
77if ( num1 > num2 ) {
8- console . log ( "num 1 is greater than num2" ) ;
8+ console . log ( "num 1 is greater than num2" ) ;
99} else {
10- console . log ( "num 1 is not greater than num2" ) ;
10+ console . log ( "num 1 is not greater than num2" ) ;
1111}
1212
1313console . log ( "I am regular bottom code" ) ;
1414
15-
1615// Checking if a string is equal to another string:
1716
1817let username = "chai" ;
1918let anotherUsername = "chai" ;
2019
2120if ( username != anotherUsername ) {
22- console . log ( "Pick another username" ) ;
21+ console . log ( "Pick another username" ) ;
2322} else {
24- console . log ( "Didn't get any username" ) ;
23+ console . log ( "Didn't get any username" ) ;
2524}
2625
27-
28-
2926// Checking if a variable is the number or not:
3027
3128let score = 44 ;
3229
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" ) ;
3532} else {
36- console . log ( "No that is not a number" ) ;
33+ console . log ( "No that is not a number" ) ;
3734}
3835
3936let arr = [ ] ;
4037
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" ) ;
4340} else {
44- console . log ( "This is array" ) ;
41+ console . log ( "This is array" ) ;
4542}
4643
47-
4844// Checking if a boolean value is true or false:
4945
5046let isTeaReady = false ;
5147
5248if ( isTeaReady ) {
53- console . log ( "Tea is Ready" ) ;
49+ console . log ( "Tea is Ready" ) ;
5450} else {
55- console . log ( "Tea is not ready !" ) ;
51+ console . log ( "Tea is not ready !" ) ;
5652}
5753
58-
5954// Check if an array is empty or not:
6055
6156let items = [ ] ;
6257
6358console . log ( items . length ) ;
6459
6560if ( items . length === 0 ) {
66- console . log ( "Array is empty" ) ;
61+ console . log ( "Array is empty" ) ;
6762} else {
68- console . log ( "Array is not empty" ) ;
63+ console . log ( "Array is not empty" ) ;
6964}
7065
71-
7266// INFO: Switch & Case
7367const dayNumber = 5 ;
7468
7569switch ( 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" ) ;
9387}
9488
9589// INFO: Ternary Operator
9690dayNumber == 0 ? console . log ( "It is true..." ) : console . log ( "It is false..." ) ;
9791
9892const gender = "F" ;
99- const userMessage = `${ gender === "F" ? "She" : "He" } is a college student.`
93+ const userMessage = `${ gender === "F" ? "She" : "He" } is a college student.` ;
10094console . log ( userMessage ) ;
10195
102-
103-
10496// INFO: If and else statements
10597let age = 20 ;
10698if ( age >= 20 ) {
107- console . log ( "You are an adult..." ) ;
99+ console . log ( "You are an adult..." ) ;
108100} else if ( age >= 13 ) {
109- console . log ( "You are a teenager..." ) ;
101+ console . log ( "You are a teenager..." ) ;
110102} else {
111- console . log ( "You are a child..." ) ;
103+ console . log ( "You are a child..." ) ;
112104}
113105
114-
115106// INFO: Switch Case Statements
116107let day = "Monday" ;
117108switch ( 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." ) ;
130121}
131122
132-
133123// INFO: Loops
134124// for loop
135125for ( let i = 0 ; i < 5 ; i ++ ) {
136- console . log ( i ) ;
126+ console . log ( i ) ;
137127}
138128
139129// while loop
140130let i = 0 ;
141131while ( i < 5 ) {
142- console . log ( i ) ;
143- i ++ ;
132+ console . log ( i ) ;
133+ i ++ ;
144134}
145135
146136// Do while loop
147137let a = 0 ;
148138do {
149- console . log ( a ) ;
150- i ++ ;
139+ console . log ( a ) ;
140+ i ++ ;
151141} while ( i < 5 ) ;
152142
153-
154143// for of
155144const fruits = [ "Apple" , "Banana" , "Cherry" ] ;
156145for ( const fruit of fruits ) {
157- console . log ( fruit ) ;
146+ console . log ( fruit ) ;
158147}
159148
160-
161149// for-in
162150const person = { name : "Alice" , age : 25 } ;
163151for ( const key in person ) {
164- console . log ( key + ": " + person [ key ] ) ;
152+ console . log ( key + ": " + person [ key ] ) ;
165153}
166154
167-
168155// INFO: Break and continue
169156for ( let i = 0 ; i < 5 ; i ++ ) {
170- if ( i === 3 ) break ;
171- console . log ( i ) ;
157+ if ( i === 3 ) break ;
158+ console . log ( i ) ;
172159} // 0 1 2 break will exists the loop;
173160
174-
175161for ( let i = 0 ; i < 5 ; i ++ ) {
176- if ( i === 3 ) continue ;
177- console . log ( i ) ;
162+ if ( i === 3 ) continue ;
163+ console . log ( i ) ;
178164} // 0 1 2 4 continue skips the current iteration
179165
180-
181166// NOTE: Quizes
182167
183168// INFO: Quiz 1
184169let x = 5 ;
185- if ( x = 10 ) {
186- console . log ( "x is 10" ) ;
170+ if ( ( x = 10 ) ) {
171+ console . log ( "x is 10" ) ;
187172} else {
188- console . log ( "x is not 10" ) ;
173+ console . log ( "x is not 10" ) ;
189174} // x is 10
190175
191176// INFO: Quiz 2
192177const numbers = [ 1 , 2 , 3 , 4 , 5 ] ;
193178for ( let i in numbers ) {
194- if ( i == 2 ) break ;
195- console . log ( i ) ;
179+ if ( i == 2 ) break ;
180+ console . log ( i ) ;
196181} // 0 1
197182
198-
199183// INFO: Quiz 3
200184let z = 0 ;
201185while ( z < 3 ) {
202- console . log ( z ) ;
203- z ++ ;
186+ console . log ( z ) ;
187+ z ++ ;
204188} // 0 1 2
205189
206190// INFO: Quiz 4
207191let count = 0 ;
208192do {
209- console . log ( count ) ;
210- count ++ ;
193+ console . log ( count ) ;
194+ count ++ ;
211195} while ( count < 0 ) ; // 0
212196
213197// INFO: Quiz 5
214198let value = 0 ;
215199for ( let i = 0 ; i < 5 ; i ++ ) {
216- if ( i % 2 === 0 ) continue ;
217- value += i ;
200+ if ( i % 2 === 0 ) continue ;
201+ value += i ;
218202}
219203console . log ( value ) ; // 4
220204
221205// INFO: Quiz 6
222206let output = "" ;
223207switch ( "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" ;
233217}
234218console . log ( output ) ; // banana orange
235219
236220// INFO: Quiz 7
237221for ( 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+ }
242226} // 0 0, 1 0, 2 0
243227
244228// INFO: Quiz 8
245229let c = 0 ;
246230while ( c < 3 ) {
247- if ( c === 1 ) continue ;
248- console . log ( c ) ;
249- c ++ ;
231+ if ( c === 1 ) continue ;
232+ console . log ( c ) ;
233+ c ++ ;
250234} // 0 2
251235
252236// INFO: Quiz 9
253237let count1 = 0 ;
254238do {
255- console . log ( ) ;
256- count1 ++ ;
257- if ( count1 === 2 ) break ;
239+ console . log ( ) ;
240+ count1 ++ ;
241+ if ( count1 === 2 ) break ;
258242} while ( count1 < 5 ) ; // 0 1
259243
260244// INFO: Quiz 10
261245let result = 0 ;
262246for ( 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+ }
268252}
269253console . log ( result ) ; // 5
270-
271-
0 commit comments