0
Q:

javascript if else

if (condition1) {
  // code to be executed if condition1 is true
} else if (condition2) {
  // code to be executed if the condition1 is false and condition2 is true
} else {
  // code to be executed if the condition1 is false and condition2 is false
}
19
if (condition1) {
  //  block of code to be executed if condition1 is true
} else if (condition2) {
  //  block of code to be executed if the condition1 is false and condition2 is true
} else {
  //  block of code to be executed if the condition1 is false and condition2 is false
}
37
var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}
27
if (condition) {
  //  block of code to be executed if the condition is true
 } else {
  //  block of code to be executed if the condition is false 
 }

//example
var money = 200;
var price = 159;

if (money >= price) {	//if money is higher or equal to price
  alert("you have enough money")
} else {
  alert("you don't have enough money")
}


// you can add another condition to the else
if (age < 18) {
  alert("too young")
} else if (age > 80) {
  alert("too old")
}
1

if (hour < 18) {

    greeting = "Good day";

 }
else {

    greeting = "Good evening";

 }
 
5
if (5 < 10) {
	console.log("5 is less than 10");
} else {
	console.log("5 is now bigger than 10")
}
6
let A = 1;
let B = 0;
if (A == 1 || B == 1){
  	// some code here
}
4
/* Shorten if-else by ternary operator*/
const go = "yes"
let race = null

race = go === "yes" ? 'Green Light' : 'Red Light';
0

if (condition) {

  //  block of code to be executed if the condition is true

 }

 
5
if (pros < 10) {
  console.log("LESS THAN 10 PROS!");
}
else if (pros < 5) {
  console.log("LESS THAN 5 PROS!");
}
else {
  console.log("How many pros are there?");
}
0

if (hour < 18) {

    greeting = "Good day";

 } 
4
if (condition) {

} else if (other_condition) {

} else {

}
0

New to Communities?

Join the community