Rock, Paper, Scissors

Hi guys, could u help me with that issue im having in https://www.codecademy.com/courses/learn-javascript/projects/rock-paper-scissors?action=resume_content_item, rock paper scissors challenge?
getUserChoice = function(userInput) {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’ || userInput === ‘bomb’) {
return userInput;
}
else {
console.log(‘Your choices are rock, paper, or scissors.’);
}
function getComputerChoice() {
var randomNumber = (Math.floor(Math.random() * 3))
switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
}
function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return ‘The game is a tie’;
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return ‘The computer has won!’;
} else {
return ‘The user has won!’;
}
}
if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return ‘The computer has won!’;
} else {
return ‘The user has won!’;
}
}
if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return ‘The computer has won!’;
} else {
return ‘The user has won!’;
}
}
function playGame() {
var userChoice = userInput;
var computerChoice = getComputerChoice();
console.log('You threw: ’ + userChoice);
console.log('The computer threw: ’ + computerChoice);
}
the console says });
^
SyntaxError: Unexpected token ) im not really sure whats the issue im staring at the code for an hour now

1 Like

Hello and welcome on the forums,
There were only a few problems with the code, they were only just that you forgot to close the brackets at the endo of the functions.
The first one is that you forgot to close the getUserChoice function.
The second one was the determineWinner function where you forgot to close another bracket

Here is the code if you need it:

getUserChoice = function(userInput) {
  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
    return userInput;
  } else {
    console.log('Your choices are rock, paper, or scissors.');
  }
}
function getComputerChoice() {
  var randomNumber = (Math.floor(Math.random() * 3))
  switch (randomNumber) {
    case 0:
      return 'rock';
    case 1:
      return 'paper';
    case 2:
      return 'scissors';
  }
}
function determineWinner(userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'The game is a tie';
  }
  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'The computer has won!';
    } else {
      return 'The user has won!';
    }
  }
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors') {
      return 'The computer has won!';
    } else {
      return 'The user has won!';
    }
  }
  if (userChoice === 'scissors') {
    if (computerChoice === 'rock') {
      return 'The computer has won!';
    } else {
      return 'The user has won!';
    }
  }
}
function playGame() {
  var userChoice = userInput;
  var computerChoice = getComputerChoice();
  console.log('You threw: ' + userChoice);
  console.log('The computer threw: ' + computerChoice);
}
// I called the function for testing if everything is okay
console.log(determineWinner(getUserChoice('scissors'), getComputerChoice()));

Hope this helps :grinning:

And just one thing if you are posting code on the forums don’t forget to format it like:

console.log('hello')

Besides something going wrong with your closing brackets at some of your functions. You may want to look into your playGame() function, you are not passing any variables into it let alone calling getUserChoice() inside it.

1 Like

Here’s my code if you are interested:

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
    return userInput;
  } else {
  return console.log('Invalid choice, pick rock, paper or scissors.')
  };
};

function getComputerChoice() {
  var randomNumber = Math.floor(Math.random() * 3);
  switch (randomNumber) {
    case 0:
      return 'rock';
      break;
    case 1:
      return 'paper';
      break;
    case 2:
      return 'scissors';
      break;
  };
};

//console.log(getComputerChoice());

function determineWinner(userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'It\'s a tie!';
  } else if (userChoice === 'rock' && computerChoice === 'paper') {
    return 'You Lose! The computer won!';
  } else if (userChoice === 'paper' && computerChoice === 'scissors') {
    return 'You Lose! The computer won!';
  } else if (userChoice === 'scissors' && computerChoice === 'rock') {
    return 'You Lose! The computer won!';   
  } else {
    return 'Winner Winner Chicken Dinner! You won!'
  };
};

//console.log(determineWinner('paper','rock'));

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

playGame('bomb');

1 Like

Hello and thanks for your reply. I copied the code you posted, to see if its working fine, but it still gives me error, this time
Preformatted textvar userChoice = userInput;
^
ReferenceError: userInput is not defined
at playGame
i just added playgame at the end. Oh and how to format the text, the way you shown, sorry imma little bit sleepy

1 Like

As I said, you need to look into playGame :wink:

1 Like

Awww, thank you very much for your reply, sir! I boosted my CPU clock with some chocolate and now i see where is the problem. Fixed it, so thanks, though, i didn’t noticed it in the guide. Maybe i just didn’t understand it. Anyway thanks a lot! Also is there any way to see syntax mistakes highlighted or something. Becuase its not so clear in the console

2 Likes