9. Rock Paper Scissors ... no lizard, or spock


#1


JavaScript 9. Next Steps


I am getting this Unexpected Token Syntax Error so I cannot move on. I have been looking for an hour, but I cannot find the unexpected token. I would really appreciate it if someone with a fresh pair of eyes would take a look.

Thank you

SyntaxError: Unexpected token (


var userChoice = prompt("Do you choose rock, paper or scissors?");
function (userChoice) {
if (userChoice==="Rock") {
    userChoice = "Rock";
    }
    else if (userChoice === "Paper"){
        userChoice = "Paper";
        }
        else if (userChoice === "Scissors"){
            userChoice = "Scissors";
            }
            else{
                return "Please select either rock, paper, or scissors to proceed"
            }
}
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
function compare(choice1, choice2) {
    if (choice1===choice2) {
        return "The result is a tie!"
        }
    else if (choice1 === "rock") {
        if(choice2==="scissors") {
            return "rock";
            }
            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"};
        }
    
    }
    
    
    console.log(compare);
    compare(userChoice, computerChoice);


#2

Hi!

You are yet to give this function quoted below a name. Looks like you only defined its expected parameter.

A function is defined either:

function function_name (parameter1, parameter2) {
    // The function block here
}
``` 

or 

```
var function_name = function (p1, p2) {
    // The function block here
}

Argh! I hope this helps... :wink:


#3

semicolon is missing.

see your brace.

same here.


#4

you can missing the name of course, it makes it an anonymous function.


#5

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