Syntax Error with Rock, Paper, Scissors - Computer Choice Part 2


#1



Hi, I keep receiving the following error message but cannot figure out what I am doing wrong. Any help is sincerely appreciated.

SyntaxError: Unexpected token {


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

if (computerChoice <= 0.33) {
    computerChoice = "rock";
    
} else if (computerChoice <= 0.67) {
    computerChoice = "paper";
    
} else (computerChoice <= 1) {
    computerChoice = "scissors";
};


#2

your problem here:

else (computerChoice <= 1) {

You can't use condition with else. If you want to use condition, should be elseif.


#3

Thanks for your help Denys!


#4

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