What is choice1 is paper? unexpected token{


#1

here is my code i cannot find what is wrong it keeps giving me syntax error unexpected token {

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


#2

else does not take an argument. Else is run when none of the ifs are satisfied.

if(1 === 1){
    //do this
}else if{
    //do this
}else{
    //do this
}

#3

now its telling me invalid or unexpected token.. here is full code

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.33) {
computerChoice = "rock";
}
else if (computerChoice >= 0.33) {
computerChoice = "paper";
}
else if (computerChoice >= 0.67) {
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 == "scissors) {
if(choice2 == "rock) {
return "rock wins"
}
else {
return "scissors wins"
}
}
}


#4

In these two lines, you didn't close your strings.


#5

i feel stupid thank you


#6

There are some things that are easy to miss. When you're actually working in an actual IDE, these things will be easier to see. You'll also get better at picking out and not making those errors as you get better.


#7

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