What is wrong in this code. (runnerAge>18 && registeredEarly) ? (raceNumber+=1000) : /*Do Nothing */;

let raceNumber = Math.floor(Math.random() * 1000);

let registeredEarly = true;

let runnerAge = 10;

(runnerAge>18 && registeredEarly) ? (raceNumber+=1000) : /*Do Nothing */;

Can someone help me to find out an error in the above line, looks ok to me?

Hello @rajivprasad623192626, welcome to the forums! Ternary expression’s else (:) must do something, otherwise it will throw an error. In you case, raceNumber will have 1000 added to it if the condition is true, but it doesn’t do anything if the condition isn’t true.

thanks for your remark. In that case, it is better to use an if-condition

1 Like