Oops, try again. Your code returned 'rock wins' instead of 'scissors wins' when the inputs are paper and scissors


#1

this is my code ive been stuck for hours i really need help pls

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 === "scissors") {
       return "rock wins"; 
   }
    else {
        return "paper wins";
}
   var compare = function (choice1, choice2) {
    if (choice1 === "paper") {
        
       return "its a tie";
    }
    else if (choice2 === "rock") {
         if (choice2 === "rock"); 
        return "paper wins";
    }
    else {
       return "scissors wins";
}
}
};

this is the error message
Oops, try again. Your code returned 'rock wins' instead of 'scissors wins' when the inputs are paper and scissors


8. What if choice 1 is scissors need help
#2

You have 2 compare function and in both the else if is not quite right. Maybe have a look at the hint on 6/9
PS: And please don't hijack other peoples threads but make one questions.


#3

idk how to post, so it would be great if you could tell me how


#4

From the exercise you have problems on you print the Q&A button end up in the category of the exercise. And there in the top right should be a plus "new topic" button.


#5

and btw i tried to take out one of the compare functions and gave me an error like before it would let me type in either rock, paper, or scissors and if i took it out it wont anymore so i put it back in


#6

i found it thank you for telling me


#7

Yes because the interior of both have some mistakes on it. So I'd recommend that you have a look at the hint of ex. 6/9. And at least get rid of one compare function as otherwise the second will just overwrite the first one.