Javascript - SWITCH/AND/OR game
by vishalvasani
JavaScript
//Source: http://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/6?curriculum_id=506324b3a7dffd00020bf661
//Prompt a user and receive an input. Use the ".toLowerCase" or ".toUpperCase" to make sure that the responses come in a unified format.
var user = prompt("You've come across a troll. Do you Fight, Pay, or Run?").toLowerCase();
//Use the "switch" function to respond appropriately. Add some conditional statement such as OR and AND to make a deeper, more dynamic game.
switch(user){
case 'pay':
var twenty = prompt("Are you willing to pay $20?").toLowerCase();
var cash = prompt("Can you pay in cash?").toLowerCase();
if (cash === "yes" && twenty === "yes"){
console.log("Great, please pay and pass safely");
} else {
console.log("I will only accept $20 in cash. Prepare to die.");
}
break;
case 'fight':
var weapon = prompt("Do you have any weapons?").toLowerCase();
var smart = prompt("Are you intelligent?").toLowerCase();
if (smart === "yes" || weapon === "yes") {
console.log("Congrats, you've defeated the troll.");
} else {
console.log("You fucked up. The troll wrecked your shit");
}
break;
case 'run':
var fast = prompt("How fast can you run 1 mile in (minutes)?");
var zigzag = prompt("Can you keep this pace up for 2 miles?");
if (fast < 6 && zigzag === "yes"){
console.log("Congrats, you ran away");
} else {
console.log("You were too slow and got killed");
}
break;
default:
console.log("I am sorry, you need to either say 'yes', 'no', or 'maybe'");
}