Hey guys! I'm looking to create a prompt that re-runs each time that you provide input. (I will eventually create a 'quit' option)
In this example, the player gives their name and the computer responds. Then I want to computer to ask again, forever, but without crashing the computer.
I thought that by using the "quit" variable above, I could tell the game to stop and that the prompt would pause the infinite loop and wait for a response, but that isn't happening.
The goal: I am building a small zork-like game that allows the player to walk into various rooms, at which point to room prompt, "What would you like to do?". I've gotten most of it figured out, but if a player chooses an option that does not have useful result (like doing a jig), I want to the room will ask again, "What would you like to do?" instead of the loop just ending.
In this example, the player gives their name and the computer responds. Then I want to computer to ask again, forever, but without crashing the computer.
Code:
var user = prompt("What is your name?");
var quit = 0;
do {
quit = 1;
switch(user.toLowerCase()) {
case 'tommy':
console.log("Cool name.");
quit = 0;
break;
case 'sarah':
console.log("I know a girl named Sarah!");
quit = 0;
break;
case 'jordan':
console.log("Wow, that's my name, too!");
quit = 0;
break;
default:
console.log("Something isn't right...");
quit = 0;
}
}
while (quit = 0);
The goal: I am building a small zork-like game that allows the player to walk into various rooms, at which point to room prompt, "What would you like to do?". I've gotten most of it figured out, but if a player chooses an option that does not have useful result (like doing a jig), I want to the room will ask again, "What would you like to do?" instead of the loop just ending.