Rock,paper,scissors step 11 issue

Hello everyone, I’m having issues on step 11 of the exercise
when I get to the logging the results at the very end
console.log(determineWinner(‘paper’, ‘scissors’))
the part after the comma isn’t letting me make ‘scissors’ a string whatsoever. I went back to see if maybe its because the argument isn’t working but I followed the video from the lesson to a T and still no luck.

1 Like

Hello @tag9212138442, welcome to the forums! Could you post a link to the exercise, and your code? Also, if you have any error messages, either from the learning environment, or from the code itself, could you post them as well?
How to format your code in posts:
Press this button:


and type or paste your code in between the back ticks:
Screen Shot 2020-05-02 at 14.06.13

Hello,
I have been having the exact same issue and have not been able to resolve it myself. Any help would be much appreciated.

Thanks,
B.

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 'scissors';
    case 2:
      return 'paper';
  } 
};

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === comupterChoice) {
    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 {
      return "Congratulations, you won!";
    }
  }
};

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

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors-javascript

const getUserChoice= userInput => {
  userInput = userInput.toLowerCase();
    if(userInput=== 'rock'|| userInput==='paper' || userInput==='scissors'){
      return userInput

    }else{
      console.log('error,please type:rock paper or scissors')
 }
}
const getcomputerChoice= () => {
 const randomNumber=Math.floor(Math.random() *3)
  switch(randomNumber){
    case 0:
      return 'rock;'
      case 1:
      return 'paper'
      case 2: 
      return 'scissors'
  }
 
  };

console.log(getcomputerChoice())
  
  
  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 'congrats you won'
        }
  } if(UserChoice=== 'paper'){
      if(computerChoice ==='scissors'){
        return 'sorry computer won!'
      }else{
        return 'congrats you won!'
      }
    } if (UserChoice=='scissors'){
        if(computerChoice==='rock'){
          return'sorry computer won'

        }else{
          return 'you won'
        }
    }
  }
console.log(detemineWinner('paper','scissors'))

see the very last line with the console.log statement is where I have issues

I don’t see a function with that name in your code. That line also throws the following error:

ReferenceError: detemineWinner is not defined

When I run your code, I see the following error:

ReferenceError: comupterChoice is not defined

It comes from this line:

Where in the function do you define comupterChoice? (Notice that userChoice doesn’t throw an error.)

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

this is the correctly spelled function, scissors will register its a string after I put the comma in. I can run the code with just ‘paper’ and it will output to console. What shows up on my end is: ‘paper’, ‘scissors’)) but the first quotation after the comma will not allow scissors to be a string, it just stays white instead of yellow. The quotation at the end randomly makes the parenthesis yellow.

When I run your code posted above with the correct spelling of the function, I get the following output:

rock;
sorry computer won!

I wouldn’t worry about the colors of various text showing up in the editor unless you are receiving error messages.

Thanks for your help I tried running it and it runs correctly. I just don’t understand why the colors will change in the editor like that sometimes.

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return 'This game is a tie!';
  } 
  if (userChoice === 'rock') {
    if (computerChoice === 'paper')
      return 'Computer won!';
  } else {
    return 'Congratulations, you won!';
  }

 if (userChoice === 'paper') {
    if (computerChoice === 'scissors')
      return 'Computer won!';
  } else {
    return 'Congratulations, you won!';
  }

  if (userChoice === 'scissors') {
    if (computerChoice === 'rock')
      return 'Computer won!';
  } else {
    return 'Congratualtions, you won!';
  }
};


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

I am having the same issue, when userChoice is “paper” and computerChoice is “scissors” I still get the userChoice as winner which should not be the case.

Adding console.log() statements will shed some light on what is happening. If you don’t know what is happeing, it’s a lot harder to find the bug. When you have multiple return statements returning the same values, it’s not easy to know which one is being executed. Doing something like below helps. Give it a try.

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    console.log('return #1'); //debug print
    return 'This game is a tie!';
  } 
  if (userChoice === 'rock') {
    if (computerChoice === 'paper')
      console.log('return #2'); //debug print
      return 'Computer won!';
  } else {
    console.log('return #3'); //debug print
    return 'Congratulations, you won!';
  }

 if (userChoice === 'paper') {
    if (computerChoice === 'scissors')
      console.log('return #4'); //debug print
      return 'Computer won!';
  } else {
    console.log('return #5'); //debug print
    return 'Congratulations, you won!';
  }

  if (userChoice === 'scissors') {
    if (computerChoice === 'rock')
      console.log('return #6'); //debug print
      return 'Computer won!';
  } else {
    console.log('return #7'); //debug print
    return 'Congratualtions, you won!';
  }
};

//computer should win first three, and the last should be a tie
console.log(determineWinner('paper', 'scissors'));
console.log(determineWinner('scissors', 'rock'));
console.log(determineWinner('rock', 'paper')); //added this test case
console.log(determineWinner('rock', 'rock'));