Stuck in "Rock, Paper, Scissors" project

Hello,

first time posting, still learing how to navigate in this new environment, so please don’t be too harsh.
I’ve been cruising through the JavaScript course and got stuck in RPS project. I’ve been writing it and comparing to the tutorial video, but got stuck at 11. task.

My code looks like this:

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'scissors' || userInput === 'paper') {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 = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return "Game ended in a tie.";
    }

  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return "Computer won.";
    } else {
      return "User won.";
    }
  }

  if (userChoice) === 'paper' {
    if (computerChoice === 'scissors') {
      return "Computer won.";
    } else {
      return "User won."
    }
  }

  if (userChoice) === 'scissors' {
    if (computerChoice === 'rock') {
      return "Computer won.";
    } else {
      return "User won."
    }
  }
}  

console.log(determineWinner('paper', 'scissors'));
  

And instead of any viable result it returns:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:33
  if (userChoice) === 'paper' {
                  ^^^

Given that "if (userChoice) === ‘paper’ " is a part of second subfunction (?), I’m not sure why it doesn’t work.

You have closed the brackets a little early, so your === 'paper' isn’t actually included inside of the if conditional! The same has been done on the === 'scissors one, but not your === 'rock' one.

1 Like

Thanks, it’s actually quite baffling, how easy it is to overlook such crucial typos :open_mouth: .

I’m having the same problem. It only runs paper:

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

if (userInput === ‘rock’ || userInput === ‘scissors’ || userInput === ‘paper’) {
return userInput;
} else {
console.log(‘Error, please type: rock, scissors or paper’);
}
}
console.log(‘paper’);

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 = (userChoice, computerChoice) => {
if( userChoice === computerChoice) {
return ‘This game is a tie!’;
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’)
return “Sorry, computer won!”;
} else {
return “Congratulations, you won!”;
}

if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’){
return “Sorry, computer won!”;
} else {
return “Congratulations, you won!”;
}
}

if (userChoice === ‘scissors’) {
if(computerChoice === ‘rock’) {
return “Sorry, computer won!”;
} else “congratulations, you won!”;
}
};
const playGame = () => {
const userChoice = getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log('The comuter threw: ’ + computerChoice);

console.log(determineWinner(userChoice, computerChoice));
}
playGame();

Just here, you were missing a couple of curly brackets and it was throwing the whole thing off! I have inserted them in bold, fix this and your code should run as intended.

Thanks. I was wondering what was going on. I tried coming through. Now I’m having problems with Whale Talk.

what is going on with this code? I don’t understand. I watched the video and even tried doing it verbatim and it is coming out in error. In the video, he declares ‘vowels’, but then in the loop he has vowels, vowel . . . I’m getting frustrated . . . LOL help! I just stopped, because I keep getting errors. Then I think that I lost track of {}. His example ends with 4 } and when I end up with 4 closing curly’s at the end, it gives me the red error.

const input = ‘Hi, big, cute, killer, whale’;
const vowels = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’];
let resultArray = ;

for(let inputIndex = 0; inputIndex < input.length; inputIndex++) {
//console.log("inputIndex = " + inputIndex);
for(let vowel = 0; vowel < vowels.length; vowel++){
//console.log("vowels = " + vowels);
} if(input[inputIndex] === vowels[vowels]) {
if(input[inputIndex] === ‘e’){
resultArray.push(‘ee’) {
else if (input[inputIndex] === ‘u’){
resultArray.push(‘uu’);
}

} else {
resultArray.push (input[inputIndex]);
}
}
}