5. Both Choices are the same HELP!


#1


5. Both Choices are the same!


SyntaxError: Unexpected token =


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


#2

That error message should draw your eye to any and all = symbols in your code. Make sure they belong where they are and do what you mean for them to do.


#3

Did that and I had 4 = with the if statement. Fixed that and then
Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.
showed up


#4

Never mind, fixed it all was missing an exclamation mark. Thanks for the help


#5

You're good at debugging :slight_smile:


#6

I am up to 8. What if choice1 is scissors and it comes up with SyntaxError: Unexpected token else
I followed your advice and looked at all of the else's in my code and I couldn't see anything wrong with it? Could you help? My code is below

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

#7

I see 2 issues in your 2nd else if code block that don't occur in the 1st or 3rd. Look closely.


#8

I fixed the quotation marks around the rock but it still says SyntaxError: Unexpected token else


#9

Good eye, now think about what comprises your 'else if' code blocks.


#10

Thanks, I put in the } at the end. Thanks for the help


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.