JSFiddle - React, Tailwind, and code Playground
JavaScript
var options = ["rock","paper","scissors"],
userChoice;
while (userChoice = prompt("Do you choose rock, paper or scissors?")) {
console.log(options.indexOf(userChoice.trim().toLowerCase());
// stop asking if answer is valid
if (options.indexOf(userChoice.trim().toLowerCase()) >= 0) break;
// otherwise, inform user of error and continue asking
confirm("Error. You should input rock, paper or scissors!");
}
alert("You chose " + userChoice + ".");