As I was working on my "Rock Paper Scissors" game in JavaScript, I am running into an issue. No matter which option I choose, I am always getting the same result (e.g. You Win popup will appear no matter if I choose Rock, Paper, or scissors). I am not getting any error messages. Is there any problem with the "check" function of my code?
Here's my code:
//Variables
let rock = document.getElementById('rock');
let paper = document.getElementById('paper');
let scissors = document.getElementById('scissors');
let choices = [rock, paper, scissors];
let compChoice = Math.random();
let userChoice = '';
// Win/lose function
function check () {
if (userChoice = rock) {
if (compChoice <= 0.34 /*rock*/) {
alert('Tie');
} else if (compChoice > 0.34 && compChoice <= 0.67 /*paper*/) {
alert ('You Win');
} else if (compChoice > 0.67 /* scissors */) {
alert('You Lose');
}
} else if (userChoice = paper) {
if (compChoice <= 0.34 /*rock*/) {
alert('You Win');
} else if (compChoice > 0.34 && compChoice <= 0.67 /*paper*/) {
alert ('Tie');
} else if (compChoice > 0.67 /* scissors */) {
alert('You Lose');
}
} else if (userChoice = scissors) {
if (compChoice <= 0.34 /*rock*/) {
alert('You Win');
} else if (compChoice > 0.34 && compChoice <= 0.67 /*paper*/) {
alert ('You Lose');
} else if (compChoice > 0.67 /* scissors */) {
alert('Tie');
}
}
}