8. What if choice 1 is scissors


#1


I'm just a little lost. I'm sure it's because I'm missing a bracket or something like that but I can't find any mistakes.


SyntaxError: Unexpected token else


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 {
    return "paper wins"
}

};


#2

you can't have to else statements right next to each other


#3

this was good:

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

now add another else if to check if choice1 is scissors, inside the else if nest an if and a else to check for choice2, just like you did in two previous exercises


#4

/*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 === "rock") {
return "rocks wins"}

else {
return "scissors wins"
}
}
}

updated code - I'm getting the error "unexpected token else"


#5

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

if (choice2==="rock") {
return"paper wins"
}
else {
return "scissors wins"
}
// missing } to close else if
else if (choice1 === "scissors") {

see comment in code


#6

2 posts were split to a new topic: 8. what if choice1 is scissors


#7