Rock Paper Scissors in javascript

**I am stuck in rock paper scissors
it gives error
you threw:rock
computer threw:scissors
‘It’s a Tie’
undefined
**

let userChoice = prompt('Do you want to choose : rock, paper or scissors');
// comupter Choice
let  computerChoice = Math.random();
if(computerChoice < 0.33 ){
    computerChoice = 'rock';
}
else if(computerChoice <=0.67) {
    computerChoice = 'paper';
}
else{
    computerChoice = 'scissors'
}
function determineWinner(userChoice,computerChoice){
   if(userChoice === computerChoice){
        console.log("It's a Tie!");
    }
    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!';
       }
    }
}
console.log('You threw : ' + userChoice);
console.log('Computer threw : ' + computerChoice);
console.log(determineWinner());

Hello @java0741927131. Welcome to the forums. This may be the error you are looking for:

The determineWinner() function accepts two parameters userChoice, computerChoice. In your function call, however, you provide no parameters. This will cause undefined, as there is nothing for the function to go on, if you will.

Fun fact

In Python, if you don’t provide enough parameters, it will throw an error. In JS, however, it return undefined!

1 Like

Hi there, welcome to the forums. :slight_smile:

I’ve added a line to your program:

See the line I’ve highlighted in orange? Its output on the console is also highlighted in orange. As both userChoice and computerChoice are undefined, your function is correctly logging the “It’s a tie!” response.

You might have forgotten a couple of parameters when you called that function. :slight_smile:

Edit: Haha, didn’t see you were also replying there @tera5288723178 :smiley:

2 Likes