8/9 Unexpected end of input


#1


8/9 stuck


SyntaxError: Unexpected end of input


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

compare(userChoice, computerChoice);


#2

Where is the rest of your code?


#3

/*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"
}
} else if (choice1 === "sissors") {
if (choice2 === "rock") {
return "rock wins"
} else {
return "scissors wins"
}
};

compare(userChoice, computerChoice);

It was still commented out so I didn't think that it mattered. But yeah I'm just trying to figure out where I went wrong here instead of copying and pasting someone else's (exactly) from the other forums.


#4

If you bring your code in readable syntax you will see the error easy

var compare = function(choice1, choice2) { // here open a function
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 if (choice1 === "sissors") 
{
    if (choice2 === "rock") 
    {
        return "rock wins"
    } 
    else 
    {
    return "scissors wins"
    }
}
}; // and here i put a closing curly bracket in

Like you can see a closing curly bracket was missing in the end for your function or your last else if


#5

Thanks mate, much appreciated.


#6

May I just say a heartfelt thanks to codmakr for the most valuable advice! "If you bring your code in readable syntax you will see the error easy"
This was the key to showing me my error.


#7

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