SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

SyntaxError: expected expression, got keyword 'else'

Altcademy Team wrote on 7 February 2018


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

I would appreciate it if some one could pint out what I am missing here. thanks

Answer
Should use lowercase if (not If) for all conditional (if...else statements).
This should work
var computerChoice; if (computerChoice <= 0.33) { computerChoice = "rock"; } else if (computerChoice < 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; }

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026