JavaScript: build rock paper scissor:Error: Your code returned 'paper wins' instead of 'rock wins' when the inputs are rock and scissors


#1


I had made a mistake in my coding for building the rock paper scissor game on js exercise:

I have seem to overwritten the comparison if/else if statement prior two exercise however i some how cleared that. Now I am getting the error :Your code returned 'paper wins' instead of 'rock wins' when the inputs are rock and scissors
Can any one help me the below mentioned code is what i have written

/*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("Computer: " + computerChoice);*/

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


#2

HI this line

if(choice2==="scissor")

you wrote scissor instead of scissors


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.