Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 946fdcf

Browse filesBrowse files
committed
Add examples and syntax for if-else-if statements in script.js
1 parent 57372e0 commit 946fdcf
Copy full SHA for 946fdcf

File tree

Expand file treeCollapse file tree

1 file changed

+29
-1
lines changed
Filter options
  • JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals
Expand file treeCollapse file tree

1 file changed

+29
-1
lines changed

‎JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals/script.js

Copy file name to clipboardExpand all lines: JAVASCRIPT BASICS/Variables In JS/2-Operators & Conditionals/script.js
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ console.log(5 >> 2); //1 [5/2/2 = 1]
327327
/* The if statement is used to execute a block of code if a condition is true.
328328
329329
Syntax:
330+
330331
if(condition){
331332
//block of code
332333
} */
@@ -362,6 +363,7 @@ if(speed <= 50){
362363
/* The if-else statement is used to execute a block of code if a condition is true.
363364
364365
Syntax:
366+
365367
if(condition){
366368
//block of code
367369
}
@@ -384,7 +386,7 @@ else{
384386

385387
let Age = 3;
386388

387-
if(age > 18){
389+
if(Age > 18){
388390
console.log('I can Drive');
389391
}
390392
else{
@@ -393,6 +395,32 @@ else{
393395

394396
//output: I cannot Drive
395397

398+
//3. if-else-if Statement:
399+
400+
/* The if-else-if statement is used to execute a block of code if a condition is true.
401+
402+
Syntax:
403+
404+
if(condition1){
405+
//block of code
406+
}
407+
else if(condition2){
408+
//block of code
409+
}
410+
else{
411+
//block of code
412+
} */
413+
414+
let weight = 65;
415+
416+
if (weight > 70) {
417+
console.log("You are Overweight");
418+
} else if (weight > 50 && weight <= 70) {
419+
console.log("You are Fit");
420+
} else {
421+
console.log("You are Underweight");
422+
}
396423

424+
//Output: You are Fit
397425

398426

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.