#8 your code returned paper wins instead of underfined


#1



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


your code returned paper wins instead of underfined.


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if ( 0 <= computerChoice && computerChoice <= 0.33) {
	computerChoice = "rock";
} else if(0.33 < computerChoice && 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 === "paper")
        if (choice2 === "rock"){
            return "paper wins"
        }
        else {
            return "scissors wins"
        }

        else if (choice1 === "scissors")
        if (choice2 === "rock"){
            return "rock wins"
        }
        else {
            return "paper wins"
        }
        else if (choice1 === "rock")
        if (choice2 === " scissors"){
            return "rock wins"
        }
        else {
            return "paper wins"
        }
        };
        
        console.log( compare(userChoice, computerChoice) );

that is my original code and I get the correct answer when I run it, it just gives me the undefined error. Also I tried to add a opening and closing bracket for all the else if and it would just give me a syntax error,


#2

Who is supposed to win if choice1 === "scissors" and choice 2 === "paper"?


#3

This is all I have to say ... -.-


#4

Did it work? :smile:


#5

I had this same problem and discovered that it is case sensitive, so if you capitalize your selection in the beginning when it prompts you, it won't work because everything is defined as all lowercase.
For example, when it asks me what I want to be, I was entering "Rock" instead of "rock," so it gave me "undefined" as the result but still told me I had the correct answer.


#6

:)) depend's how strong it's that paper


#7

yes it did thank you so much for pointing that out or it would have been another 5 days of me trying to figure out where I went wrong.


#8

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