Getting multiple answers when running Rock, Paper, Scissors code. e.g. "rock" "rock"


#1

On a couple of occasions I've noticed that when running the code on this program I've got multiple answers. Like so:

rock
rock

or

rock
scissors

So instead of getting one answer, I'm getting two. When I run the code it's accepted as correct and I can move on, but I'm hoping that someone can enlighten me as to what's happening in the code.

This code returns "rock" twice:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log(computerChoice)
console.log (userChoice)

var compare = function (choice1, choice2)
{
if (choice1===choice2)
{
return ("The result is a tie!");
}
else if (choice1==="rock")
{
if (choice2==="scissors")
{
return ("rock wins");
}
else
{
return ("paper wins");
}
}
else if (choice1==="paper")
{
if (choice2==="rock")
{
return ("paper wins");
}
else
{
return ("scissors wins");
}
}
};


#2

Two console.logs might be the reason + it is not the result, you are not calling out the function itself, so basically the game is not playing. You only output both choices.


#3

This should be:
console.log("Computer: " + computerChoice)

I see what I've done now. I've logged two separate choices here, instead of logging the one choice the computer is making.