Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Need Infinite Loop to Pause and Re-Prompt Player each time it runs.

Sethorion

Towns Guard
Xy$
0.00
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.

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);
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.
 

Saif

Towns Guard
Xy$
0.00
If I may recall, for conditional statements, you cannot use a single operator since it is only used for assigning values. An example would be:

variable = 0; (Assigning the value 0 to the variable)
variable == 0; or variable === 0; (Checking if the variable has the value of 0)
 
Top