0
Q:

how to make an if statement in javascript

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 (expression) {
   Statement(s) to be executed if expression is true
} else {
   Statement(s) to be executed if expression is false
}
0
if(condition1) { //runs if the condition is true
  //type what you want to happen if the condition is true
}else if (condition2) {
  //type what you want to happen if the condition is true
} else { //If no condition is true it will run this
  //type what you want it to do
}
0

New to Communities?

Join the community