Rock Paper Scissors

This is my code for R,P,S and I keep getting undefined when I console.log(determineWinner)
I’ve watched the walkthrough videos but I don’t see my error.

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if(userInput === ‘rock’ || userInput === ‘paper’ || userInput ===‘scissors’) {
return userInput;
} else {
console.log(‘Error’);
}
}

const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
};

const determineWinner = (getUserChoice,getComputerChoice) => {
if(getUserChoice === getComputerChoice)
return ‘Draw’
}
if (getUserChoice === ‘rock’) {
if(getComputerChoice === ‘paper’) {
return ‘lose’
} else {
return ‘win’;
}
}

if (getUserChoice === ‘paper’) {
if(getComputerChoice === ‘scissors’) {
return ‘lose’
} else {
return ‘win’;
}
}

if (getUserChoice === ‘scissors’) {
if(getComputerChoice === ‘rock’) {
return ‘lose’
} else {
return ‘win’;
}
}

console.log(determineWinner(‘rock’, ‘scissors’));
console.log(determineWinner(‘paper’, ‘rock’));
console.log(determineWinner(‘scissors’, ‘paper’));

Hi, I noticed that when running your code, your ‘strings’ are not being read as such.

I believe you might be using the wrong character to represent the start and end of strings.

I’m new to coding however what I’ve noticed so far is that the colour change in the text is an indicator.

For example when you’ve put userInput === ‘rock’, rock is showing as the same as userInput which wouldn’t be right.

I haven’t continued with the rest of the points in the task, however if you try that first you may find once you set up the playGame function and call it, it may work

Hi, there!

Have you figured out the problem?

If not, take a look at your curly brackets and make sure all of them are accounted for. :wink:

Note:

If code is copied and pasted, some sites will not register strings as a string and the quotes will need to be manually added. There is no problem with using single quotes if you prefer them. :slight_smile:

Haven’t figured it out yet so I’m going to start from scratch.

I mentioned that you should look at your curly brackets as a hint.

You are missing a beginning { which also leaves you missing a } at the end of your determineWinner function.

It was so cluttered to me I had to start over but I saw the solution you said after the fact. Thank you!

1 Like