JavaScript if else and else if
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
}
0
10
if (condition) {
// block of code to be executed if the condition is true
}
//-------------
if (hour < 18) {
greeting = "Good day";
}
//-------------
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
}
//-------------
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
//-------------
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
Thank you!
10
0
3.7
10
if (condition1) {
// block of code to be executed if condition1 is true
} else {
// block of code to be executed if the condition1 is false
}
Thank you!
10
0
Are there any code examples left?
New code examples in category Javascript