Rock, paper, scissors JavaScript game doesn't work

Hi
I am stuck, I am new into programming and have issues with this excercise, it doesnot show display anything, no errors, no game.
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput===‘paper’ || userInput===‘scissors’){
return userInput;
} else {
console.log(‘There is an error.’);
}
};

const computerChoice = Math.random();
if (computerChoice <= 0.33){
return ‘paper’;
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66){
return ‘rock’;}
else {
return ‘scissors’;
}
const compare = (choice1 , choice2) =>{
if (choice1 === choice2){
return ‘Tie’;
}
else if (choice1 === ‘paper’){
if (choice2 === ‘rock’){
return ‘paper wins’;
}
else {
return ‘scissors wins’
}
}
else if (choice1 === ‘scissors’){
if (choice2 === ‘paper’){
return ‘scissors wins’;
}
else{
return ‘rock wins’;
}
}
else if (choice1 === ‘rock’){
if (choice2 === ‘scissors’){
return ‘rock wins’;
}
else {
return ‘paper wins’;
}
}
}
const playGame =()=>{

userInput(‘scissors’);
computerChoice(‘rock’);

console.log(compare(userInput, computerChoice));
}
playGame();
That’s my code.

I’m guessing this is supposed to be a function. Near the bottom of your code, you call computerChoice(‘rock’); but this won’t work because you’ve already assigned computerChoice to a constant in the quoted code block above.

Try fixing your computerChoice function and see if that fixes it.

Total aside: 0.333… thru 0.339… is unclaimed and will therefore default to ‘scissors’. Why use floats at all. Floor the random and use it as an index in a list of choices. Failing that, use fractions in an if else…

if x < 1 / 3...
else if x < 2 / 3...
else...
1 Like