Race daya challange

hello guys i have a problem with the day race code my else if statement is not giving me the right output can i get some help please . its suppose to give me a number that is in 1723 not 723

Hi there,

let registeredEarly = false;

Because registerdEarly is false, line 7 comes back as false–preventing 1000 from being added to the raceNumber.

let raceNumber = Math.floor(Math.random()* 1000 is global scope right ?

if so why does the code on line 13 just pick it up from the global scope ?

Yes–which is why line 14 is logged to the console.
Not quite sure where you think your code isn’t working? (But I would add a final else that considers all runners under the age of 18)

let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = false;
let Age = 20;

if (registeredEarly == true && age >= 18) {
  raceNumber += 1000;

if(Age >= 18 && registeredEarly === true) {
  console.log(`Your race number is ${raceNumber} and you will race at 9:30am`);
} else if(Age > 18 && !registeredEarly) {
  console.log(`Your race number is ${raceNumber} and you will race at 11am`);

The runner is older than 18 but didn’t register early, so while line 7 checks true for the age check, registeredEarly comes back false–which is why 1000 is not added to the raceNumber. Then line 11 is checking the same thing, also returning false, continuing to line 13 which returns true–logging line 14 to the console.

On the other hand, if registeredEaly is true–then line 7 is true (adding the 1000) and line 12 logs to the console.

1 Like

Brother thank you so much understood your are a star

1 Like