0
Q:

js if

if(a == 'value'){
    doSomething();
    if(b == 'another value'){
        doAnotherThing();
    }
}
4
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
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

if (condition) {

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

 }

 
5

if (hour < 18) {

    greeting = "Good day";

 } 
4
if (32 == 32) {
	console.log('32 is equil to 32!');
}
0
int a = 100;
int b = 100;
if (a < b){
  print("a is less than b") // This will run because 1 < 2
  }
else{
  //This only runs if the condition for the if statement is not met
  print("a is greater than or equal to b")
  }
-1

New to Communities?

Join the community