4. P2. SyntaxError: Unexpected token '{'. Parse error


#1


I'm stuck at 4. Part 2: Build "Rock, Paper, Scissors"


Error message:

"SyntaxError: Unexpected token '{'. Parse error."

I can't figure out what brackets I have messed up, or what is wrong. The help is appreciated. :slight_smile:


var userChoice = prompt("Do you choose rock, paper, or scissors?")
var computerChoice = Math.random()
console.log(computerChoice)
if (computerChoice < 0.34) {
    computerChoice = "rock"
} else if (computerChoice > 0.66) {
    computerChoice = "scissors"
} else (computerChoice) {
    computerChoice = "paper"
} console.log("Computer" + computerChoice)


#2

hi @corerockstar66114

this is solid code nice job :slight_smile:
You don't actually have a syntax error with braces per se, instead the problem is that you are trying to perform a condition check in your else statement.
If it may help please see the sample below

var userChoice = prompt("Do you choose rock, paper, or scissors?")
var computerChoice = Math.random()
console.log(computerChoice)
if (computerChoice < 0.34) 
{
    computerChoice = "rock"
} 
else if (computerChoice > 0.66) 
{
    computerChoice = "scissors"
} 
else 
{ //you can't check for conditions in else 
    computerChoice = "paper"
} console.log("Computer " + computerChoice) //added a space here just for appearance nothing else

#3

Hey mike_in_training,

Haha it's always something so simple of course.

I appreciate the help! :slight_smile: I'll have to remember that for future reference. <3

Regards,
crs


#4

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