mercredi 9 septembre 2020

Run if statement checking if string value is different than defined strings

this is my first post on stack overflow and I'll try to make it concise.

I'm trying to write a Rock, Paper, Scissors game in javascript. I would like to run a certain code to notify the user when input is not correct so I tried to compose an if statement that would run when the user input is different than "ROCK", "PAPER" or "SCISSORS" but it runs no matter what the input is.

Here is my snippet :

function userPlay() {
  let userChoice = prompt("Make your move")
  userChoice = userChoice.toUpperCase()

  console.log(userChoice) // Check the variable's value

  if(userChoice !== "PAPER" || userChoice !== "ROCK" || userChoice !== "SCISSORS"){
   alert("Not an option")
   userPlay()
 }
  return userChoice

}

I've tried to google but I'm not sure how to formulate my search and could mainly find if statements that check if value is equal to (===) as opposed to value is different of (!===).

I hope I managed to be clear enough and I hope I didn't just make a stupid typo ;)

Regards Morgan

Aucun commentaire:

Enregistrer un commentaire