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`);
}
//An if statement can be followed ba an optional else statement, which
//executes whe the Boolean expression is false
if(Boolean_expression) {
// Executes when the Boolean expression is true
}else {
// Executes when the Boolean expression is false
}
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'
>> number=23
>> guess = input('Enter a number : ')
>> if guess == number:
>> print('Congratulations! You guessed it.')
>> elif guess < number:
**( It is giving me 'Invalid Syntax')**
>> else:
**( It is also giving me 'Invalid syntax')**
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
}