Rock,Paper,Scissors (lesson 7) "unexpected token { " *stuck for days...please help!*


#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"; 
}
    if (choice1 === "paper") {
        
    else if (choice2 === "rock") {:confused:
        return "paper wins";
    }  
    else { 
        return "scissors wins";
};

#2

else if(choice1 === "rock") {
        
    if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins"; 
}
    if (choice1 === "paper") {

your missing another } after the else case to close the else if case. Other wise the following code will still be inside the else if giving you errors about the impossible situation of 2 else following each other. I see that you fixed this by using another if instead but that is really not the solution rather fix your {}.


#3

haxor, can you have a function without {}?
the function deceleration:

var compare = function(choice1,choice2)

doesn't have {}

@ibcarp, after your else:

else {
        return "paper wins"; 
}

you are missing a } to close your else if(choice1 === "rock") {


#4

No you can for loops and condition (under certain circumstances) but for functions they're mandatory, good point.