RockPaperScissors project: Help with comparing numbers in if/else

https://www.codecademy.com/courses/introduction-to-javascript/projects/rock-paper-scissors-javascript?action=resume_content_item

This is step 5 on the Rock Paper Scissors project. The step asks to create a function for the computer choice. This is what I have, but when I check on the console, the numbers are not appearing right. They are random each time instead of zero being strictly rock and so on. I believe it is because the number variable is not properly being compared to the actual number. I also understand that I can just write it using switch but was wondering how to do it specifically using if/else. Can anyone help guide me in this?

const getComputerChoice = () => {
let randomNumber = Math.floor(Math.random() * 3);
if (randomNumber === 0){
return ‘rock’;
}
else if (randomNumber === 1){
return ‘paper’;
}
else {
return ‘scissors’;
}
}

console.log(getComputerChoice(0));

console.log(getComputerChoice(2));

Your function does not take any arguments as it generates its own number for the if statement.

2 Likes