8/9 - Need help getting this to run


#1
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";
    }
    }
};
    if (choice1 === "scissors") {
    if (choice2 === "rock") {
        return "rock wins";
        
    } else if (choice2 === "paper"){
        return "scissors wins";
    
    }
};
    compare(userChoice, computerChoice);
    }

#2

Hey Peterarza,

You need to remove the closing curly brace and semi-colon (};) on line 27 :)


#3

The one at the very end of this quote to be more specific (as there are no line numbers displayed). This should enable you to use else if again instead of switching to if :smile:
Also get the function call outside of the function. Here it won't work and if it works it would create some infinite loop style problems.


#4

Yes, you have to call your function outside of the function itself. Also, we never put semicolons after curly braces.


#5

We avoid it for those of conditions but we place them after statements like this:

var name = value;

even if value is something more complex like:

function(){};