9/9 Game. What's wrong with my while loop?


#1

Why loop works only with "rock"? Is there syntax mistake, or I don't know something about while loops?

var userChoice = prompt("Do you choose rock, paper or scissors?");
while ( userChoice != ("rock" || "paper" || "scissors")) {
userChoice = prompt("Choose rock, paper or scissors!");
}


#2

The condition of your while-loop

function getUserChoice(){
   var userChoice = "";
   while ( !(userChoice === "rock" ||
             userChoice === "paper" ||
             userChoice === "scissors" ) ) {
     userChoice = prompt("Choose rock, paper or scissors!");
   }
   return userChoice;
}
var userChoice = getUserChoice();

//
// OR
//

var userChoice ="";
while( ["rock","paper","scissors"].indexOf(userChoice) === -1) {
 userChoice = prompt("Choose rock, paper or scissors!");
}

//
// OR
//

var userChoice ="";
while( "rockpaperscissors".indexOf(userChoice) === -1) {
 userChoice = prompt("Choose rock, paper or scissors!");
}

Reference

google search
== the Book ==
javascript indexOf() site:developer.mozilla.org

== discussions / opinions ==
javascript indexOf() site:stackoverflow.com

nice to know

You could test in labs repl.it
choose Javascript
You will get a split-screen
In the left-hand-side you paste-in your code
click on the Run button.
The right-hand-side is the console

references

www.crockford.com --> for most respected guide-line in Javascript
like coding convention
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html


What if the user answers inappropriate answer?