How do I fix this? Syntax Error:"{" expected HELP ASAP


#1


syntax error: expected "{" why and where????????

I am on lesson 6 BTW

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

#2

Hi you forgot to open the compare function with { } you should do it like that

var compare=function(choice1,choice2) { <== add one here 

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

else if(choice1==="rock")
{if (choice2==="scissors"){return"rock wins!";}
else{return"paper wins";}
}
}<== Close the compare function here

#3

OK done! one more thing...Syntax error:expecting ";" where??
How are ";" supposed to be used in java? Can you find my error?

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

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


#4

All your else if statement should be inside the compare function and you should remove the ; after the else statement like that

}
} < == you should remove this one because it close the compare function here.
compare else if (choice1==="paper") 
{ 
if(choice2==="rock")
{return"paper wins";}
else; <== remove this ;
{return "scissors wins";}
}
}  < === you should close your compare function here.

And before your else if statement remove the compare you wrote


Continued