Rock, scissors,paper project

hello Guys,

can u help me please, I m really stuck with the last part of my code,
I will share my code below maybe somebody can help me and tell me what is wrong.

const playGame = () => {
** const userChoice = getUserChoice(‘scissors’);**
** const computerChoice = getComputerChoice();**
** console.log('You threw: ’ + userChoice);**
** console.log(‘The computer threw:’ + computerChoice);**
** console.log(determineWinner(userChoice, computerChoice));**

the error is:
referenceError: getComputerChoice is not defined
at playGame (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:51:27)
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:57:1)

thank you !

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!

Difficult to say without seeing the rest of the code, the function call you attempt to make here:

 const computerChoice = getComputerChoice();

doesn’t work, because the function does not exists. This is very likely because:

typo in function name
scope issue

but please provide your full code

const getUserChoice=userInput =>{
  if (userInput ==='rock' || userInput ==='scissors' || userInput ==='paper'){
    return userInput;
    } else {console.log('error');

const getComputerChoice=() =>{
  const randomNumber=Math.floor(Math.random()*3)
  case 0:
  return 'rock'
  case 1:
  return 'paper'
  case 2:
  return 'scissors'

  const determineWinner = (userChoice,computerChoice)=>{
    if(userChoice === computerChoice){
      return "it s a tie game";
    if(userChoice ==='rock'){
      if(computerChoice ==='paper'){
        return "computer won";
      } else{
        return "u won";
      if(userChoice ==='paper'){
          return "comp won";
          return "u won";
      if(userChoice ==='scissors'){
        if(computerChoice ==='rock'){
          return "comp won";
          return"u won";

const playGame = () => {
   const userChoice = getUserChoice('scissors');
   const computerChoice = getComputerChoice();
   console.log('You threw: ' + userChoice);
   console.log('The computer threw:' + computerChoice);
   console.log(determineWinner(userChoice, computerChoice));

I was right, it is a scope issue. You nested your getComputerChoice within (the body of) your getUserChoice

also, the switch statement is outside the body of getComputerChoice function

thank you so much stetim94 :slightly_smiling_face:

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