Switch
-
Un-tangles a long if-else block.
-
Always double-check breaks.
-
With break, only execute current statements.
-
Without break, the execution will cascade down the list.
-
Default does not need a break.
-
switch, case, default, break.
switch(day) {
case "Friday":
window.location = "www.unclewoodys.net";
break;
case "Saturday":
window.location = "www.haveaniceday.com";
break;
case "Wednesday":
window.location = "homepages.uc.edu/~jonesbr";
break;
default:
window.location = "www.work.com";
}
Lab 3
Home
Internet II: Day 2