I'm brand new to learning to code and can't figure out why my below function is not working as intended. I've searched through many other questions/answers but can't seem to find a solution that works.
The goal of the below code is to have the computer choose from the array (rock, paper, scissors) and then to prompt the user to input their choice. To see if what I had so far worked, without creating the full if, else function, I simplified it for now so that the user can only win in one scenario.
Even if the computer chooses scissors and I input rock as the user which is supposed to be the winning combination - it always gives the "Hmm?" message....why?!
I thought perhaps it's because compsChoice is a number, but I can't seem to figure out how to make it a string. I tried the String() and .toString methods but they did not work - maybe I wrote the syntax wrong...
<script>
function computerPlay() {
const gameInputs = ['rock', 'paper', 'scissors'];
let compsChoice = [Math.floor(Math.random() * gameInputs.length)];
console.log(gameInputs[compsChoice]);
}
computerPlay();
function playRound (compsChoice, userSelection) {
userSelection = prompt ("Rock, Paper or Scissors?");
// only alerts HMM no matter what...
if (userSelection === 'rock' && compsChoice === 'scissors') {
alert ('You WIN!');
} else {
alert ('HMM?');
}
}
playRound();
</script>