I can't call in my function. Gives me a syntax error. Anyone know whats worng?


#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";
} 

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 (choice1 == "scissors") {
        if (choice2 == "paper") {
            return "Scissors wins!";
        }
        else {
            return "Rock wins!";
        }
    }
}
console.log("User's Choice: " + userChoice);
console.log("Computer's Choice: " + computerChoice);
compare(userChoice, computerChoice);

#2

No conditions after else better use another else if here.


#3

thanks a lot dude, i just thought that if it was the last else I shouldn't use else if and I tought that the functions inside it didn't count. Thanks again


#4

You could have used else but then else would cover any cases left meaning you don't need a condition after it.