Syntax Error... What if choice1 is paper?


#1

I keep getting syntax error and I don't know why?

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

#2

Send me the link of the lesson, please


#3

Remove the /* before var userChoice.
Remove ; after every {. Semi-colons (;) act as periods for JavaScript.

I hope this helps!
If it does, click the "Solved" button below this reply.


#4

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


#5

You do know that it's part of it to put the /* and */. Also just giving me the answer would help too. If you don't know what the actual answer is, then don't answer at all.


#6

Remove the ; after all the open brackets {. Also remove it after every closing bracket except the last one. Also, not trying to be rude, but were not going to give you an answer you can copy and paste. That negates any learning which is what this platform is designed to do.

If removing the ; doesn't fix it, try removing the () around your strings. I'm a javascript noob but I don't think the're necessary. If they are necessary someone please correct me :smiley:


#7

I do know that the if and else if statements need brackets around them, but I did that and it still says syntax error. I do python and I'm still confused


#8

Here's my updated 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==="paper"){
        if(choice2 === "rock") {
            return "paper wins";
        };
        else {
            return "scissors wins";
        };
    };
};

#9

Oh, I see. You're missing a branch of the else if statement.

add another part like whats above, but for else if(choice 1 === "rock")

Also need to remove some more ;


#10

Here is the correct code. Some of that code was unneeded, but I just learned that you don't need to put a ; after the }. Thank you.

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

#11

Actually, I do know the answer, I just forgot to mention it. After beginning the if / else if / else conditions, he should remove the ; after {. But please, I have no grudge against anyone.


#12

And yes, I didn't see ghughes13 already said the answer.