Getting unexpected end of input on rock, paper, scissors lesson


#1

I'm getting the "SyntaxError: Unexpected end of input" on the console, wherever i submit my "rock, paper, scissors" code, i've used the hint but doesn't help..i even copied the code from the hint, but still, nowhere..

I see the unenxpected end of input on the console, even though my code looks right..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("Computer: " + computerChoice);*/
var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!"
}

if(choice1 === choice2) {
    return "The result is a tie";
}

else if(choice1 === "rock") {

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

}


#2

why do you have this twice:

if (choice1 === choice2) {
        return "The result is a tie!"
}

anyway, the error is caused by the fact that your function doesn't have a matching closing curly bracket:

var compare = function(choice1, choice2) { <-

i indicate it with an arrow (<-), that opening curly bracket doesn't have a matching closing curly bracket


#3

I've fixed the code, but didn't work..Sorry for that double though..must be the copied hint..
the code below is the changed one..

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

#4

You didn't add a closing curly bracket to close the function...., like i told you


#5

I just fixed it, i restarted, and tried to make the code again, and it works! I was just confused of so many curly brackets, but fixed it, it's ok now, thank for the help, @stetim94 ....Im now, on the 'for' loops!