9. Next Step - Rock Paper Scissors Lizard Spock


#1

Hey Guys,

I cannot for the life of me debug my code. I am trying to do the Big Bang Theory's "Rock, Paper, Scissors, Lizard, Spock" game. It is giving me a Syntax Error : Unexpected EOF. Below is my code, any help would be awesome!

var userChoice=prompt("Do you choose rock, paper, scissors, lizard, or spock?");

var computerChoice = Math.random();

    if (computerChoice <= 0.2) {
	    computerChoice = "rock";
    } else if(computerChoice <= 0.4) {
	    computerChoice = "paper";
    } else if(computerChoice <= 0.6) {
	        computerChoice = "scissors";
	} else if(computerChoice <= 0.8) {
	        computerChoice = "lizard";
	} else {
	        computerChoice = "spock";
	        
    } 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 crushes sicssors";
            } else if(choice2 === "spock") {
                return "spock vaporizes rock";
            } else if(choice2 === "lizard) {
                return "rock crushes lizard";
            }else {
                return "paper covers rock";
                    }
                }
    else if(choice1==="paper") {
            
            if(chioce2 === "rock") {
                return "paper covers rock";
            } else if(choice2 === "spock") {
                return "paper disproves spock";
            } else if(choice2 === "lizard") {
                return "lizard eats paper";
            } else {
                return "scissors cut paper";
                    }
                }
    else if(choice1 === "scissors") {
            
            if (choice2 === "rock") {
                return "rock crushes sicssors";
            } else if(choice2 === "lizard") {
                return "scissors decapitates lizard";
            } else if(choice2 === "spock") {
                return "spock smashes scissors";
            } else {
                return "scissors cuts paper";
                    }
                }
    else if(choice1 === "lizard") {
        
            if (choice2 === "rock") {
                return "rock crushes lizard";
            } else if(choice2 === "paper") {
                return "lizard eats paper";
            } else if(choice2 === "scissors") {
                return "scissors decapitates lizard";
            } else {
                return "lizard poisions spock";
                    }
                }
    else if(choice1 === "spock") {
        
            if (choice2 === "rock") {
                return "spock vaporizes rock";
            } else if(choice2 === "paper") {
                return "paper disproves spock";
            } else if(choice2 === "scissors") {
                return "spock smashes scissors";
            } else {
                return "lizard poisions spock";
                    }
                }          
    };
    
compare(userChoice,computerChoice);

#2

What the error says and im pretty sure you only needed rock paper and scissors dont know if that can create error.


#3

@puccinin,

You are forgetting 1 closing-double-quote-"
in

} else if(choice2 === "lizard) {

#4

I found the error. I was missing a " after lizard in the else if statement

if(choice2 === "scissors") {
                return "rock crushes sicssors";
            } else if(choice2 === "spock") {
                return "spock vaporizes rock";
            } else if(choice2 === "lizard) {
                return "rock crushes lizard";
            }else {
                return "paper covers rock";
                    }
                }

Now when I run the code, I am able to actually play. The only problem is that on some of the rolls I get a new error message.

ReferenceError: Can't find variable: choice2.

This happens specifically when the user picks paper and the computer picks scissors. Any ideas?
It's part of the else statement so that wouldn't need a defined variable?


#5

Thanks for the heads up! Now when I run the code, I am able to actually play. The only problem is that on some of the rolls I get a new error message.

ReferenceError: Can't find variable: choice2.

This happens specifically when the user picks paper and the computer picks scissors. Any ideas?
It's part of the else statement so that wouldn't need a defined variable?


#6

Nice it looks fun never played with lizard or spock :smile: )


#7

@puccinin,

Have a close look at

chioce2


#8

Maybe choice2 === "rock"