Skip to content

Commit 1158d68

Browse files
committed
control flow code files
1 parent 6c721e5 commit 1158d68

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

04_control_flow/one.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// if
2+
3+
const isUserloggedIn = true
4+
const temperature = 41
5+
6+
// if ( temperature === 40 ){
7+
// console.log("less than 50");
8+
// } else {
9+
// console.log("temperature is greater than 50");
10+
// }
11+
12+
// console.log("Execute");
13+
// <, >, <=, >=, ==, !=, ===, !==
14+
15+
// const score = 200
16+
17+
// if (score > 100) {
18+
// let power = "fly"
19+
// console.log(`User power: ${power}`);
20+
// }
21+
22+
// console.log(`User power: ${power}`);
23+
24+
25+
// const balance = 1000
26+
27+
// if (balance > 500) console.log("test"),console.log("test2");
28+
29+
// if (balance < 500) {
30+
// console.log("less than 500");
31+
// } else if (balance < 750) {
32+
// console.log("less than 750");
33+
34+
// } else if (balance < 900) {
35+
// console.log("less than 750");
36+
37+
// } else {
38+
// console.log("less than 1200");
39+
40+
// }
41+
42+
const userLoggedIn = true
43+
const debitCard = true
44+
const loggedInFromGoogle = false
45+
const loggedInFromEmail = true
46+
47+
if (userLoggedIn && debitCard && 2==3) {
48+
console.log("Allow to buy course");
49+
}
50+
51+
if (loggedInFromGoogle || loggedInFromEmail) {
52+
console.log("User logged in");
53+
}

04_control_flow/switch.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// switch (key) {
2+
// case value:
3+
4+
// break;
5+
6+
// default:
7+
// break;
8+
// }
9+
10+
const month = "march"
11+
12+
switch (month) {
13+
case "jan":
14+
console.log("January");
15+
break;
16+
case "feb":
17+
console.log("feb");
18+
break;
19+
case "march":
20+
console.log("march");
21+
break;
22+
case "april":
23+
console.log("april");
24+
break;
25+
26+
default:
27+
console.log("default case match");
28+
break;
29+
}

04_control_flow/truthy.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const userEmail = []
2+
3+
if (userEmail) {
4+
console.log("Got user email");
5+
} else {
6+
console.log("Don't have user email");
7+
}
8+
9+
10+
// falsy values
11+
12+
// false, 0, -0, BigInt 0n, "", null, undefined, NaN
13+
14+
//truthy values
15+
// "0", 'false', " ", [], {}, function(){}
16+
17+
// if (userEmail.length === 0) {
18+
// console.log("Array is empty");
19+
// }
20+
21+
const emptyObj = {}
22+
23+
if (Object.keys(emptyObj).length === 0) {
24+
console.log("Object is empty");
25+
}
26+
27+
// Nullish Coalescing Operator (??): null undefined
28+
29+
let val1;
30+
// val1 = 5 ?? 10
31+
// val1 = null ?? 10
32+
// val1 = undefined ?? 15
33+
val1 = null ?? 10 ?? 20
34+
35+
36+
37+
console.log(val1);
38+
39+
// Terniary Operator
40+
41+
// condition ? true : false
42+
43+
const iceTeaPrice = 100
44+
iceTeaPrice <= 80 ? console.log("less than 80") : console.log("more than 80")

0 commit comments

Comments
 (0)