6/9 - Syntax Error


#1

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

Can anyone identify my mistake?
Thank you!


#2

Hey! First of when you post a code in this site just select over your code and hit CTRL + K so it gets organized and we can see it more clearly. Secondly your problem is that you didnt do your brackets on your code stated below!


#3
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 (choic2==="scissors"); {
            return "rock wins";
        };
        else {
            return "paper wins";
        };
    };
};

indent preformatted text by 4 spaces

#4

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

hey! you mean like this? ^


#5

Hey @salekeen,

There should be no semi colons before the first corresponding bracket, and after the loop/function.

All of those have semi colon problems, and one of them even has a bracket problem.

Also you spelled choice2 wrong here. :smiley:


#6

Yes @salekeen. And @ragezapper Explained you more too!


#8

You should probably delete that code. We dont want users just copying the code and advancing.