I need some help with Step 6 of Rock paper scissors: What if choice1 is rock?


#1

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

}

SyntaxError: Unexpected token function

any help is appreciated, Thank you


#2

Not sure if it was intentional but you commented out this top section with /* and */:

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);

Your missing {} on this function. Check bold text and comments for fixes

var compare = function(choice1,choice2){ // no need for choice 1 and 2 in " " and remember to close the function at the end of this section:

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

else if(choice1 === "rock") {
if(choice2 === "scissors") {
return "rock wins" ; // semicolon
}
else {
return "paper wins" ; // semicolon
}
}
}; // curly bracket + semicolon, close the function

Hope this helps, tested it for you. Yes you can miss out the semicolons but its best not to.