ARG! syntax error on lesson 6, please help!


#1



Please help!! I am stuck at lesson 6, "What if choice1 is rock?"


I keep getting "Oops, try again. There was a problem with your syntax." when I try to save and submit my code!
here is my code:

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

I can't seem to find out what is is the problem?


#2

Hi you should add one } at the end for closing the compare function


#3

thanks so much, i did that and it worked right away!:joy:


#4

@wizmarco
thanks so much again of the help. I was wondering if you could help me again. i'm on lesson 8 "what if choice1 is scissors". when i try to save and submit my code it gives me the error message "Oops, try again. There was a problem with your syntax." i look at lots of posts but still can't find the problem.
here is my code:

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 === "scissors") {
                     
                     if (choice2 === "paper"){
                         return "scissors wins";
                     }
                     else {
                         return "rock wins";
                     }
                 }
             }
         
        }
};
console.log( compare(userChoice, computerChoice) );

#5

you shouldn't closed the else if statement at thend but just after the else statement
your first else if statement should be

else if (choice1 === "paper") {
    if (choice2 === "rock") {
        return "paper wins";
    } 
    else {
        return "scissors wins";
    }
}#here you should closed the else if statement

else if (choice1 === "scissors") {
...

do the same for the second else if statement then remove two } a the end of your code


#6

@wizmarco
ok, i did that but it is still giving me the same error code :rage:. here is my revised code.

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 === "scissors") {
                     
                     if (choice2 === "paper"){
                         return "scissors wins";
                     }
                     else {
                         return "rock wins";
                     }
};
console.log( compare(userChoice, computerChoice) );

#7

you remove more then two } at the end.... just add one more


#8

Ya! i got it to work! i just had to put another curly brace at the end! thanks so much, you are a life saver