Skip to content

Instantly share code, notes, and snippets.

@varjmes
Last active December 24, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varjmes/6757870 to your computer and use it in GitHub Desktop.
Save varjmes/6757870 to your computer and use it in GitHub Desktop.
Playing with Switch & Case Statements.
var user = prompt("An elderly lady approaches you, brandishing a sharpened umbrella. Do you FIGHT, do you RUN or do you CURL up into the fetal position?").toUpperCase();
switch(user) {
case 'FIGHT':
console.log("You'd really hurt an old lady? For shame.");
var hits = prompt("How many times will you hit her?");
var sure = prompt("Are you sure?").toUpperCase();
if (hits >= 1 && sure === 'YES') {
console.log("How Heinous. She's dead. And you're a bad person.");
} else if (hits === 0 || sure === 'NO' ) {
console.log("Admirable. I'm glad you changed your mind.");
} else {
console.log("She attacked you first. You're dead.");
}
break;
case 'RUN':
console.log("You yella-bellied foo!");
break;
case 'CURL':
console.log("She pokes you with her umbrella repeatedly until death envelopes you.");
break;
default: "You seemed to have typed an incorrect command, doofus. Try again.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment