younes
0
Q:

javascript if

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 (condition)
{
     //Block of statements here
     //These statements will only execute if the condition is true
}
 else {
	//Write the else condition
}
5
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
if( name = 'george washington'):
	print("You have the same name as the first president of the United States")
    // python 
else:
	print("You do not have the same name as George Washington")
4
var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}
27
const number = (Math.random() - 2.5) * 5;
if (number < 0) {
	console.log('Number is negative');
}
if (number = 0) {
	console.log('Number is zero');
}
if (number > 0) {
	console.log('Number is positive');
}
1
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

if (condition) {

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

 }

 
5
if (32 == 32) {
	console.log('32 is equil to 32!');
}
0

New to Communities?

Join the community