Rock Paper Scissors - Math.random & if statements not working?


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
On CodeAcademy Pro: https://www.codecademy.com/courses/learn-javascript/projects/rock-paper-scissors

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
My code ALWAYS returns:

You threw: rock
The computer threw: paper
computer wins

i.e. The computer always throws paper. I don’t think the Math and If parts are right?

```

var userInput = ‘Rock’;
userInput = userInput.toLowerCase();

function getComputerChoice() {
Math.floor(Math.random() * 3);
if (getComputerChoice = 0) {return ‘rock’};
if (getComputerChoice = 1) {return ‘paper’};
if (getComputerChoice = 2) {return ‘scissors’};
}

function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return ‘tie’;
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return ‘computer wins’
}
else {return ‘human wins’}
}
if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return ‘computer wins’
}
else {return ‘human wins’}
}
if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return ‘computer wins’}
else {return ‘human wins’}
}
}

function playGame() {
var userChoice = userInput;
var computerChoice = getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log('The computer threw: ’ + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}

playGame();

<do not remove the three backticks above>

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.