8. What if choice 1 is scissors need help


#1

it says " SyntaxError: expected expression, got keyword 'else' ", here is my code where did i go wrong:
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 "Rock wins!"
} else {
return "Scissors wins"
}
}
}
}


#2

else if(choice1 === "Paper") {
 if(choice2 === "Rock") {
 return "Paper wins!"
 } else {
 return "Scissors wins!"
 }
//missing a closing bracket here.

Add a closing bracket there and you should be good to go

Check all of your opening and closing brackets.

 }
 }
 }  //This looks a little suspicious. again check your Opening/Closing brackets.
 }

#3

for some reason still not wrking and there is a closing bracket where you said
I STILL NEED HELP PLEASE :sob:


#4

Can you repost your edited code so I can see the changes you've made?


#5

ok here is my edited code and it now says for the syntax error expected expression get keyword 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 if(choice1 === "Scissors") {
if(choice2 === "Rock") {
return "Rock wins!"
}
else {return "Scissors wins!"}
}
}
}
}


#6

else if(choice1 === "Paper") {
if(choice2 === "Rock") {
return "Paper wins!"
} else {
return "Scissors wins!"
}

I believe you're missing a closing bracket after this to close this else-if statement.


#7

I tried what u said it still not work. i need o ask you a favor... if you already did this lesson, (rock paper scissors 1, 8. what if choice 1 is scissors) please save me a lot of amateur pain and copy and paste all of your code from that lesson onto your response, but only if you already did the lesson?
Thank you so much.


#8

in other words, can i have your code for this lesson?


#10

A post was split to a new topic: Oops, try again. Your code returned 'rock wins' instead of 'scissors wins' when the inputs are paper and scissors


#11

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 "rock wins";
    }
    else {
        return "scissors wins";
    }
}
}

#12

What is this a question or a solution? One would need more information to make use of this. Also if it is a question please edit a title one the first line then I can move this into a separate topic which is more useful than hijacking a question.