Please help! I have been trying to find the extra brace(s), and I have 25 open and 25 close all the way it should be. Why then do I get "SyntaxError: Unexpected token {" error?


#1


var validateInput = function()
{
    var userChoice = prompt("Do you choose rock, paper or scissors?")
    if(userChoice != "rock" && userChoice != "paper" && userChoice !=          "scissors" && userChoice != "rope")
    {
        return validateInput()
    }
    else
    {
        return userChoice;
    }
};
validateInput();

var computerChoice = Math.random();

if (computerChoice < 0.25) 
{
	computerChoice = "rock";
} 
else if(computerChoice <= 0.50) 
{
	computerChoice = "paper";
}
else if(computerChoice <= 0.75)
{
    computerChoice = "rope";
}
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 if (choice2 === "rope"
        {
            return "rock wins";
        }
        else
        {
            "paper wins";
        }
    }
    else if (choice1 === "paper")
    {
        if (choice2 === "rock")
        {
            return "paper wins";
        }
        else if (choice2 === "rope"
        {
            return "paper wins";
        }
        else
        {
            return "scissors wins";
        }
    }
    else if (choice1 === "rope")
    {
        if (choice2 === "rock")
        {
            return "rope wins";
        }
        else if (choice2 === "paper")
        {
            return "rope wins";
        }
        else
        {
            return "scissors wins";
        }
    }
    else if (choice1 === "scissors")
    {
        if (choice2 === "rock")
        {
            return "scissors wins";
        }
        else if(choice2 === "rope")
        {
            return "scissors wins";
        }
        else (choice2 === "paper")
        {
            return "scissors wins";
        }
    }
};

compare(userChoice,computerChoice);

**SyntaxError: Unexpected token {**

Replace this line with your code.


#2

You didn't use a closing parenthesis and the next symbol is a curly brace so its unexpected. :slight_smile:


#3

Thank you very much!! You have super attention to details!!


#4

No problem! You get used to the type of errors that occur, so you know what to look for. :slight_smile:


#5

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