Computer Choice: Part 2 - SyntaxError Unexpected token {


#1


Hi I'm stuck. Can you pls help me to identify the error?


I receive the following message when I submit my code:

SyntaxError: Unexpected token {


Replace this line with your code. 
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random(); 
If (computerChoice <= 0.33) {   
    computerChoice = "rock";
} else if (computerChoice <= 0.66) {
    computerChoice = "paper";
} else {   
    computerChoice = "scissors";
}
console.log("Computer: " + computerChoice);


#2

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);


#3

Thanks for the reply.

After I changed my computerChoice for "rock" & "paper" to < 0.34 & <= 0.67 I still receive the syntax error message.

(computerChoice < 0.34)
(computerChoice <= 0.67)

Then I realized that I had typed "If" incorrectly with an uppercase "I", instead of lowercase "i". So "if" shld be in lowercase.

The code works now :smile:


#4

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