Skip to content

Commit c503bea

Browse files
authored
Conditional Statements - If, If-else-if, Switch
1 parent 8b13732 commit c503bea

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

conditional-staements2.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Switch statements
2+
3+
let ch = "B";
4+
5+
switch (ch) {
6+
case "a":
7+
console.log(`${ch} is a vowel`);
8+
break;
9+
10+
case "b":
11+
console.log(`${ch} is a consonant`);
12+
break;
13+
14+
case "A":
15+
console.log(`${ch} is a vowel in upper case`);
16+
break;
17+
18+
case "B":
19+
console.log(`${ch} is a consonant in upper case`);
20+
break;
21+
22+
default:
23+
console.log(`${ch} is an integer`);
24+
}

conditional-statements.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Conditional Statements in JavaScript comprises of : If, If-else-If, If-else, Switch
2+
// If, If-else, If-else-If
3+
4+
let age = 13;
5+
let name = "Pranav";
6+
let favNum = "007";
7+
8+
// == operator is used to compare only values
9+
// === operator is used to compare both value and type
10+
11+
if (age >= 18 && age <= 90) {
12+
console.log("Eligible for voting");
13+
} else if (favNum === "007") {
14+
console.log("Matched");
15+
} else if (favNum == 007) {
16+
console.log("Matched but different type");
17+
} else {
18+
console.log(`The name is ${name}`);
19+
}

0 commit comments

Comments
 (0)