7. What if choice 1 is paper?


#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(choice2 === "scissors") {

        return "rock wins";
    }
}
    else { 
          return"paper wins";
    }

else if(choice1 === "paper") {

    if(choice2 === "rock") {

    return "paper wins";
}
}

else {
return "scissors wins";
}

};

it says "SyntaxError: Unexpected token else" What's wrong please!!!


#2

Hi you closed the """ else if statement "" Early Its should be close after the else statement
Like that

else if(choice1 === "rock") {

    if(choice2 === "scissors") {

        return "rock wins";
    }

    else { 
          return"paper wins";
    }
} <=== You should close the" else if statement"here

#3

I corrected it but still says there is syntax error


#4

Remove the comment /* */


#5

Sorry ?!!!! Which comment did you mean ?


#6

this ===> /*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);*/<=== this

#7

Yes, I did but still doesn't work


#8

Your code should be like that

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

#9

it still gives SyntaxError: Unexpected token else!!