The switch statement part 2

JavaScript Tutorial
Conditionals and Loops
The switch Statement
30
2/4
               

The switch Statement



Consider the following example.
var day = 2;
switch (day) {
case 1:
document.write("Monday");
break;
case 2:
document.write("Tuesday");
break;
case 3:
document.write("Wednesday");
break;
default:
document.write("Another day");
}

// Outputs "Tuesday"
Try It Yourself

You can have as many case statements as needed.
How many "case" statements are usually used in the "switch" statement?
Only 5
2 - for "true" and "false"
One for each possible answer

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2