8/9 Return statements don't appear to declare winner


#1


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

I'm not stuck. Code was approved. Not sure why return statements don't appear when game is played. Please help.


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("User: " + userChoice);
console.log("Computer: " + computerChoice);
var compare = function(userChoice,computerChoice) {
if (userChoice === computerChoice) {
    return "The result is a tie!";
    }
    else if(userChoice === "rock"){
            if (computerChoice === "scissors") {
                return "rock wins";
            }else{
                return "paper wins";
                  }
                                         }
                            
                else if (userChoice === "paper"){
                        if (computerChoice === "rock") {
                            return "paper wins";
                        }else{
                            return "scissors wins";
            }  
    }
}


#2

console.log("User: " + userChoice);

This line of code try erasing it and then saving it because it worked just fine for me.


#3

did it print "rock/paper/scissors wins"? when I play the game it only shows me what the user and computer's choices were and nothing else.


#4

Mine didn't print who wins mine just printed the computers answer


#5

I guess it's a bug. I even tried swapping all the returns out for console.log and nothing changed.


#6

So was my answer the solution???


#7

Not quite, I understand why it prints out the computer's choice. To me it's unclear why the code doesn't also print out any of the "rock/paper/scissors wins" statements.


#9

You need to call out the function after the coding.

compare(userChoice, computerChoice);


#10

Yeh, that solved my problem.


#11

the code always ran. I don't get why there isn't a "rock/paper/scissors wins" return statement printing out.


#12

Is it a capitalization error? That's what was happening to me (on the input I was capitalizing "Rock" but it's lower case in the code). You also need to add the piece arrayninja mentioned, but add console.log (I think).

console.log(compare(userChoice, computerChoice));


#13

i have the same problem too..!!!
i don't know why this is happening....


#14

thanks to @legendsoftomorrow @shenchris @juanpalmero @jonathandalby @csswhiz63937 for confirming I wasn't the only one having an issue and for working towards a solution