Another Rock, Paper, Scissors request for help

Hi Everyone,

So I completed the Rock, Paper, Scissors (with a lot of hints). What is printed out is not right at all. Even doing both as “rock” should give me a tie. Something is wrong with my switch statements I would guess but can’t figure out what. Here is the link. I will keep looking at it (which is what I’ve been doing for 3 days) to see if something comes to me. Thanks.

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

Code

const getUserChoice = userInput =>{
userInput = userInput.toLowerCase();

if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {console.log(‘rock’);
};
}
console.log(getUserChoice(‘rock’)); // should print ‘paper’

const getComputerChoice = () => {
const randomNumber = Math.floor (Math.random () * 3);

switch (randomNumber){
case 0:
return ‘rock’;
case 1:
return ‘scissors’;
case 2:
return ‘paper’;
};
}

console.log(getComputerChoice());

function detrmineWinner (getUserChoice, ComputerChoice) {
if (getUserChoice === getComputerChoice){
return console.log (‘tie’);
}

if (getUserChoice === ‘paper’) {
if (getComputerChoice === ‘scissors’) {
return ‘The computer won’;
} else {
return ‘You won!’;
}
}

if (getUserChoice === ‘rock’) {
if (getComputerChoice === ‘scissors’) {
return ‘You won!’;
} else {
return ‘The computer won’;
}
}

if (getUserChoice === ‘scissors’) {
if (getComputerChoice === ‘rock’) {
return ‘The computer won’;
} else {
return ‘You won!’;
}
}
}

console.log (detrmineWinner (‘paper’, ‘scissors’));

const playGame = () => {
const userChoice = getUserChoice(‘rock’);
const computerChoice = getComputerChoice();
console.log('You threw ’ + userChoice);
console.log('The computer threw ’ + computerChoice);
console.log(detrmineWinner(userChoice, computerChoice));
};

playGame();

PRINTS

rock
scissors
You won!
You threw rock
The computer threw paper
The computer won

Hello! The reason you are getting these results:

Is because you console.log the respective functions as tests throughout the code:

and

and

The last three lines that are logged to the console appear to be correct, though.

I hope this helps!

Thanks. Fixed that but seems once I fix one issue another comes up. Going to just start over and see if I can get it done. Will post back if I have problems.

2 Likes