Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 25, 2012 22:44
Show Gist options
  • Save jpetto/3471715 to your computer and use it in GitHub Desktop.
Save jpetto/3471715 to your computer and use it in GitHub Desktop.
JavaScript branching example
var s = Number(prompt("How old are you?"));
if (s <= 10) {
console.log("You're a young one!");
} else if (s <= 20) {
console.log("Those rowdy teen years...");
} else if (s <= 30) {
console.log("You got time, don't worry.");
} else {
console.log("Over 30? Man, hurry up and do something with your life.");
}
var l = prompt("Give me a letter");
switch (l) {
case 'a' :
case 'b' :
case 'c' :
console.log("Easy as 123!"); // this will fall through until it hits a break
case 'd' :
console.log("Dirty dog!");
break;
default :
console.log("That's a crummy letter!");
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment