title: Testing if the user input value is in a given array (JavaScript)
body: <p>I just created a five rounds rock-paper-scissors game using vanilla JavaScript. The program runs just fine so far except for the fact every time I start the game for the very first time it will take any user input as invalid no matter what and won't count that round. </p>
  
  <p>This is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Global variables
  let playerWins = 0;
  let computerWins = 0;
  let array = [];
  let validInput = 0;
  let newRound = "";
  
  // This function generates a computer selection
  const computerPlay = () =&gt; {
      array = ["rock", "paper", "scissors"]
      return array[Math.floor(Math.random() * array.length)];
  }
  
  // This function stores player selection
  const playerSelection = (selection) =&gt; {
      selection = prompt("Enter: 'Rock', 'Paper' or 'Scissors'").toLowerCase();
      validInput = array.indexOf(selection);
      console.log(validInput);
      
      // This loop will validate user input is correct
      while (validInput === -1) {
          alert("Invalid input, try again");
          selection = prompt("Enter 'Rock', 'Paper' or 'Scissors'").toLowerCase();
          validInput = array.includes(selection);
      }
      return selection;
  }
  
  // This function plays a single round of Rock-Paper-Scissors
  const playRound = (playerSelection, computerPlay) =&gt; {
  
      // If both players select the same item
      if (playerSelection === computerPlay) {
          return alert("It's a tie!");
      }
  
      // If player selects "Rock"
      if (playerSelection === "rock") {
          if (computerPlay === "scissors") {
              playerWins += 1;
              return alert("Rock crushes scissors: YOU WIN!!!");
          } else {
              computerWins += 1;
              return alert("Paper covers rock: YOU LOOSE!!!");
          }
      }
  
      // If player selects "Paper"
      if (playerSelection === "paper") {
          if (computerPlay === "rock") {
              playerWins += 1;
              return alert("Paper covers rock: YOU WIN!!!");
          } else {
              computerWins += 1;
              return alert("Scissors cuts paper: YOU LOOSE!!!");
          }
      }
  
      // If player selects "Scissors"
      if (playerSelection === "scissors") {
          if (computerPlay === "rock") {
              computerWins += 1;
              return alert("Rock crushes scissors: YOU LOOSE!!!");
          } else {
              playerWins += 1;
              return alert("Scissors cuts paper: YOU WIN!!!");
          }
      }
  }
  
  // This function keeps score and reports a winner or loser at the end
  const trackWins = (pw, cw) =&gt; {
      alert("COMPUTER WINS: " + cw + "\nPLAYER WINS: " + pw)
      if (pw &gt; cw) {
          alert("YOU WIN THIS ROUND, CONGRAX!!!")
      } else if (cw &gt; pw) {
          alert("YOU LOOSE THIS ROUND, SO BEST LUCK FOR THE NEXT TIME :_(")
      } else {
          alert("IT'S A TIE")
      }
  }
  
  // This function creates a 5 round game
  const game = () =&gt; {   
      for (let i = 0; i &lt; 5; i++) {
          playRound(playerSelection(), computerPlay());
      }
      trackWins(playerWins, computerWins);
  }
  
  do {
      game();
      newRound = prompt("Do yo want to play another round? Type 'y' to continue or any other key to exit").toLowerCase();
      
  } while (newRound === "y");
  alert("It was a good game, bye for now!")</code></pre>
  </div>
  </div>
  </p>
  
  <p>I will appreciate any ideas to fix this problem or improve my script, thank you in advance!</p>