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
}
const randomObject = 5;
if(randomObject < 2) {
console.log("The Random Object has a value more than 2");
}
else {
console.log("The Random Object has a value less than 2");
}
const count = 20;
if (count === 0) {
console.log('There are no students');
} else if (count === 1) {
console.log('There is only one student');
} else {
console.log(`There are ${count} students`);
}
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');
}
var condition = true; // An example condition for true/false conditions
if (condition == true) {
console.log('condition is true');
} else {
console.log('condition is not true');
} // Console will output 'condition is true'
if(condition){
//action to take if condition is met
} else if(condition){
//action to take if first condition is not met but there is a second condition
} else{
//actioon to take if all conditions are not met
}
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
}