6/9 issues please help! "SyntaxError: Unexpected token"


#1

var compare = function(choice1, choice2); {
if(choice1 === choice2); {
return "The result is a tie!";
}
// Beginning of else if
else if(choice1 === "rock") {

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

};


#2

It looks the same as mine:

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

};


#3

Try this:

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

-- I would also try deleting the semicolon after stating the compare function.


#4

I tried your suggestion jkenw10; thanks but didn't work. I have been looking at all the posts made for answer. It might actually be a glitch so I reported it as a bug.


#5

The problem seems to be that there should not be semicolons here:

var compare = function(choice1, choice2); {
    if(choice1 === choice2); {

neither between the function and it's { nor after the condition of the if. For the function it's just a syntax error for the if it's a little more complicated as you can read here:


#6

By god you fixed my problem!!!

Thank you very much I apologize for not reading more about the grammar and wasting everyone's time but I was very stumped.


#7

Since I had put the semi colon in the last problem 5/9 and it was accepted, was that an error though?


#8

hello haxor or anyone who is reading this post......can you please post the complete code of rock,paper,scissors ?

I keep getting error " your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper....

appreciate your help


#9

/*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);*/
function compare(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 {

}
}

/*This should work*/


#10

got it....thank you!


#11

I don't like posting code that much if it is about more than a few lines or a really short and simple problem. Otherwise one might not get the problem and proceeds without understanding what was wrong. If you get the ... instead of ... Then the best way to find the error is going through your code and have a look at which paths it takes.


#12

The one after the function should have already been an error in 5/9. For the if better have a look at the link first. For 5/9 it was ok from a syntax point of view although it behaved unexpected but by adding an else if after it, it produced an error. I tried to explain this a bit in the link but if there are open questions feel free to ask.


#13

I don't have semicolons there and its telling me that it is expecting a semicolon
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is a tie!"
}

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

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

}

#14

Well, you have to look at this:

They couldn't notice that it's a return statement, so it just takes the string, in which you have to put a semi colon, but that's not the case.