Rock, Paper, or Scissors

Hi, first time here im stumped.

Having a bit of trouble getting my rock, paper, scissors to declare a win/tie.

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

below is what is being logged:

You threw: rock
The computer threw: rock
undefined

Below is my code:

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

const computerChoice = () =>{
switch (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 'tied game';
  }
  if (userChoice === 'rock'){
    if (computerChoice === 'paper') {
    return 'Computer won';
  } else {
    return 'you won!';
    }
  }
  if (userChoice === 'paper'){
    if (computerChoice === 'scissors'){
      return 'Computer won!';
     } else {
      return 'you won!';
    }
 }
  if (userChoice === 'scissors'){
    if (computerChoice === 'rock') {
      return 'Computer Won!';
    } else {
      return 'You won';
    }
  }
};

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

playGame();

Hello @betablaster94807, welcome to the forums! Check the name of the variables you are calling determineWinner() with.

You are using userChoice and computerChoice, which are the names of functions, but you did not provide parameters or (). If you use a function this way, you are effectively asking for its name and type. So if you write console.log(userChoice), you should get something like:

>> [Function: userChoice]

Did you mean to use theses variables:

I hope this helps!

Got it, thanks for the help!

1 Like