JavaScript - Switch Statement
Switch Statement Syntax Example:
switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
default code block
}
Switch Statement Full Example:
// User enters their favorite color in the following prompt...
var color = prompt("What's your favorite primary color?","Type your favorite color here");
// The switch statement...
switch(color) {
case 'red':
console.log("Red's a good color!");
break;
case 'blue':
console.log("That's my favorite color, too!");
break;
case 'yellow':
console.log("Yellow's a good color!");
break;
default:
console.log("I don't think that's a primary color!");
}
JavaScript - Loops
For Loop Syntax Example:
for ([var i = startValue];[i < endValue]; [i+=stepValue]) {
// Your code here
}
For Loop Full Example:
var i;
for (i = 10; i >= 1; i--) {
console.log(i);
// Prints the numbers from 10 to 1
}