Rock/Paper/Scissors Issue

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

Hello, first time posting, I’ve been working on this project and I keep getting stuck. I am no longer getting errors, but when I call my playGame() function, it reads back the entire getUserChoice function script && the entire getComputerChoice function script. I have tried String Interpolation && String Concatenation with the variable. Here is what my code looks like:

// Function to determine User Input
const getUserChoice = userInput => {
  // toLowerCase function to make all userInput lowercase
  userInput = userInput.toLowerCase();

  // verfiying rock/paper/scissors
  if (userInput ==='rock' || userInput ==='scissors'|| userInput ==='paper') {
    return userInput;
  } else {
    console.log('Error: userInput invalid: ' + userInput);
  }
}

// function to determine computer choice
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) => {
  // determine if it's a tie
  if (userChoice === computerChoice) {
    return console.log('It is a ... Tie!');
  }
  if (userChoice === 'rock') {
    if(computerChoice === 'paper') {
      return console.log('The computer won this time');
    } else {
      return console.log('You\'ve won this time');
    }
  }
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors') {
      return console.log('You\'ve Lost');
    } else {
      return console.log('They\'ve Lost');
    }
  }
    if (userChoice === 'scissors') {
      if (computerChoice === 'rock') {
        return console.log('The computer has won.');
      } else {
        return console.log('Nice Job')
      }
    }
  }

const playGame = () => {
  const userChoice = getUserChoice('Paper');
  const computerChoice = getComputerChoice();

  console.log(`You threw: ${getUserChoice}`);
  console.log(`Computer threw: ${getComputerChoice}`);

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

playGame();

The result I get is:

You threw: userInput => {
// toLowerCase function to make all userInput lowercase
userInput = userInput.toLowerCase();

// verfiying rock/paper/scissors
if (userInput ===‘rock’ || userInput ===‘scissors’|| userInput ===‘paper’) {
return userInput;
} else {
console.log('Error: userInput invalid: ’ + userInput);
}
}
Computer threw: () => {
const randomNumber = Math.floor(Math.random() * 3);

switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
}
They’ve Lost
undefined

– I’m not sure what I’m doing wrong.

console.log(`You threw: ${getUserChoice}`);
console.log(`Computer threw: ${getComputerChoice}`);

You need to make sure you’re using the correct variable names in those console log statements

1 Like

It’s like magic! It works. Thank you!