Created
August 25, 2012 22:44
-
-
Save jpetto/3471715 to your computer and use it in GitHub Desktop.
JavaScript branching example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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