What if choice 1 is scissors - result not printing to console


#1

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

My code isn't returning an error message but it is not printing out the result of the game to the console. Instead it just tells me what my input is and what the computer chose. Any insight would be appreciated!


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("You: " + userChoice);
console.log("Computer: " + computerChoice);

var compare = function (userChoice, computerChoice) {
if (userChoice === computerChoice) 
{
    return "The result is a tie!";
}

else if (userChoice === "scissors")
{
    if (computerChoice === "rock")
    {
        return "rock wins"
    }
    else 
    {
        return "scissors wins"
    }
}

else if (userChoice === "paper")
{
    if (computerChoice === "rock")
    {
        return "paper wins"
    }
    else 
    {
        return "scissors wins"
    }
}

else if (userChoice === "rock") 
{
    if (computerChoice === "scissors") 
    {
        return "Rock wins"
    }
    else
    {
        return "Paper wins"
    }
}

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


#2

You called the function while it was still inside of the function. Your console.log should be outside of the brackets like this:
} };
console.log (compare(userChoice, computerChoice));


#3

Awesome! Thanks for the help


#4

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