Always returns "Paper wins!"


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


Whatever choices are made it always returns "Paper wins!"
Still, I get a "Way to go! Start next lesson" confirmation when I save and submit the code.
But obviously I must have made some error somewhere...? But why then does it behave as though my code is correct when the return obviously is faulty?


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!";
        }}
    else if(choice1 === "Paper") {
        if(choice2 === "Rock") {
            return "Paper wins!";
        } else {
            return "Scissors wins!";
        }}
    else if(choice1 === "Scissors") {
        if(choice2 === "Rock") {
            return "Rock wins!";
        } else {
            return "Scissors wins!";
        }}
}
compare(userChoice, computerChoice)


#2

OK! I figured it out myself... The first strings of rock, paper and scissors where written lower case only... once I corrected this everything was fine...
Still weird that it thought my code was correct, I'd say.
Sorry if I wasted someone's time :stuck_out_tongue:


#3

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