What if choice1 is scissors


#1


I'm having the same problem I had on a previous exercise, but I know I'm closing all of the brackets. It's giving me SyntaxError: Unexpected token else. I also am unclear on "passing in userChoice and computerChoice". Here's my code.


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

    
}};

compare(userChoice, computerChoice)


#2

Line numbers aren't included in error messages here for whatever reason, run the code in another interpreter to get something slightly more verbose:

$ xsel -b > han.js  # paste your code to a file
$ node han.js       # run with nodejs
/tmp/js/han.js:29
    else if (choice1 === "scissors") {
    ^^^^
SyntaxError: Unexpected token else

You'll have to elaborate on what you mean with that.


#3

Actually, you have the call expression written correctly. If you wish to print out the result, log the expression you have.

console.log(compare(userChoice, computerChoice));