Hello all,
I am learning JavaScript so maybe this is a no brainer for some. I am trying to make a while loop continue prompting the user until the user picks one of three choices. I am able to get the code to work fine with a single condition:
var x = prompt("Pick 1, 2 or 3");
while(x != "1"){
alert("That's not right!");
var x = prompt("Pick 1, 2 or 3");
}
alert("Cool, good job!")
As you can see I am asking the use to select 1, 2, or 3 but the condition is only met if the user selects 1. I tried to incrementally get the code to work with a change in the condition as follows:
var x = prompt("Pick 1, 2 or 3";
while(x != "1" || x != "2"){
alert("That's not right!");
var x = prompt("Pick 1, 2 or 3");
}
alert("Cool, good job!")
Sadly I create and infinite loop. I have tried many different methods and I keep failing. I think it is time for help. Can anyone show me please how to do this correctly? Much thanks.
Best Regards,
Aaron.