Point out the error in this code

can someone please point out the error in the bellow exercise?
it took me 2days to get it. (link: https://www.codecademy.com/courses/introduction-to-javascript/projects/race-day)

let raceNumber = Math.floor(Math.random() * 1000); let registeredEarly = true; let runnerAge = 20; if (registeredEarly && runnerAge > 18) { raceNumber +=1000 } if (registeredEarly && runnerAge > 18){ console.log(`Your race time will be at 9:30 am, and your race number is ${raceNumber}.`) } else if(!registeredEarly && runnerAge > 18){ console.log(`Your race time will be at 11:00 am, and your race number is ${raceNumber}.`) }; else if(runnerAge < 18){ console.log(`Your race time will be at 12:30 pm, and your race number is ${raceNumber}`) } else { console.log('Please see the registration desk.') }

Hello @css1502976869, welcome to the forums!
Notice in this bit of code, you have a semi-colon after the closing brace:

else if(!registeredEarly && runnerAge > 18){

  console.log(`Your race time will be at 11:00 am, and your race number is ${raceNumber}.`)

};

That semi-colon ends the whole if…else …else block, which means the compiler isn’t expecting an else if after it, which is why it throws the “unexpected token else” error.

Hello @css1502976869 !
It seems if you remove the semi colon above else if(runnerAge < 18), the code seems to run correctly.

nice one, thank you @css1502976869

1 Like

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