Rock paper scissors project

hi there
i ve been trying to write a code for the rock paper scissors challenge… i still get an error when trying to run it … maybe you could help me figure it out
the code looks like this

const getUserChoice = userInput => {

  userInput = userInput.toLowerCase ();

if (userInput ==='rock' || userInput === 'paper' || userInput === 'scissors') {

  return userInput;

} else {

  console.log ('invalid input')

}

}

const getComputerChoice = computerChoice => {

  computerChoice = Math.floor (Math.random ()*3)

  if (computerChoice === 0) {

    console.log ('rock')

  }else if (computerChoice === 1) {

    console.log ('paper')

  }else {

    console.log ('scissors')

  }

}

const determineWinner(userChoice, computerChoice){

  if (userChoice === computerChoice) {

    return 'It is a tie'

  }

  if (userChoice === 'rock') {

    if (computerChoice === 'paper') {

      return 'You lost'

    }else {

      return 'You win'

    }

  } 

  if (userChoice === 'scissors') {

    if (computerChoice === 'paper') {

      return 'You win'

    }else {

      return 'You lose'

    }

  } 

  if (userChoice === 'paper') {

    if (computerChoice === 'scissors') {

      return 'You lost'

    }else  {return 'You win

    }

  }

}

const playgame = () => {

 const userInput = getUserChoice ('rock');

const computerChoice = getComputerChoice()

console.log ('You threw: ' + userChoice );

console.log ('The computer threw ' + computerChoice)

console.log (determineWinner (userChoice, computerChoice))

}

playgame ()

Hi there!

I have edited your post so that the code is correctly formatted here on the forums. As a consequence, one of your errors is much easier to spot now. :slight_smile:

Go ahead and check out this post as a reference on how to format the code correctly for future topics. :slight_smile:

thank you for the effort but still…regarding my code could you help me a little more please? im kind of stuck

Hello Mikey,

I found somethings in the code:

  1. In the getComputerChoice function, you dont want to console.log the results. You want the function to return the results. Should be:
    return ‘rock’;

  2. Your function determineWinner is not declared correctly. Should be:
    const determineWinner = (userChoice, computerChoice) => {

  3. When you call the determineWinner at the end, you didn’t pass the right parameters. Should be:
    console.log (determineWinner (userInput, computerChoice))

  4. There is one console.log with the wrong input. Should be:
    console.log ('You threw: ’ + userInput );

  5. There is a if else that the string is not closed. Shoul be:
    }else {return 'You win’

If you have any doubts, just ask.

:v:t2:

thanks for your answer!!!

1 Like