I'm working on a project for one of my classes where I need to use the users input to redirect them to a website. It requires that the users choice be validated using a loop, so I've chosen to use a while loop to check for if the users input differs from what it should be and if it is, the user is prompted to re-enter their answer. Here's the code:
var websitechoice;
websitechoice = parseInt(prompt("Which website would you like to go to? \n 1. google \n 2. gmail \n 3. youtube"))
while (websitechoice != 1 || 2 || 3) {
alert("you input an incorrect value")
websitechoice = parseInt(prompt("Which website would you like to go to? \n 1. google \n 2. gmail \n 3. youtube"))
}
if (websitechoice = 1) {
alert("you chose 1")
}
else if (websitechoice = 2) {
alert("you chose 2")
}
else {
alert("you chose 3")
}
So far it was just a quick mock up I made to check if it would work, but every time I try and run it, I always get back "you input an incorrect value" even when inputting 1, 2, or 3, and so far nothing I've tried had differed the results. if anyone could help I'd really appreciate it, thanks