我是JavaScript的新手,我正在尝试制作一个小的控制流示例,但由于多个错误,它不想工作。例如,在第5行,它表示意外的令牌:
let raceNumber = Math.floor(Math.random()*1000);
let registeredEarly = true;
const runnerAge = 21;
!registeredEarly ? raceNumber += 1000;
if(runnerAge > 18){
console.log('You will race at 11:00AM with the racenumber ' + raceNumber);
} else if(registeredEarly === true || runnerAge > 18){
console.log('Yu will race at 11:00am and your racenumber is ' + racenumber);
} else if(runnerAge < 18 && !regiteredEarly){
console.log('You will race at 12:30pm and your racenumber is ' + racenumber);
} else{
console.log('Pls register at the desk.');
};
请向我解释你做了什么以及为什么,我想尽可能地学习!
在1000之后期待“:”,而不是“;”
!registeredEarly ? raceNumber += 1000 : null ;
要回答你的评论,不能跳过“:”(else),因为语法需要它。