The if else if else Statement part 2

else if



The final else block will be executed when none of the conditions is true. 

Let's change the value of the course variablein our previous example.
var course = 3;
if (course == 1) {
document.write("<h1>HTML Tutorial</h1>");
} else if (course == 2) {
document.write("<h1>CSS Tutorial</h1>");
} else {
document.write("<h1>JavaScript Tutorial</h1>");
}
Try It Yourself

The result:
You can write as many else if statements as you need.
Fill in the blanks to create a valid if...else...if statement:
var status = 1;
var msg;
 
 
 (status == 1) {
   msg = "Online";
}
 
 
 
 (status == 2) {
   msg = "Away";

else {
   msg = "Offline";
}

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2