JavaScript Race Day Project - Problem

Greetings everyone :slight_smile:

I’m working on the “Race Day Project” from the JavaScript course and I have a problem. The code runs well, but I notice that the final message ("See registration desk), which was supposed to be shown only for runners who are exactly 18 years old, keeps being shown to runners over 18 too (although it isn’t shown to the younger than 18 runners). Could anybody help me?

Race Day Project

Below is my code:

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

let early = true;
let age = 19;

if (early && age > 18) {
  raceNumber += 1000;
}

if (early && age > 18) {
  console.log(`Your race will start at 9:30, your race number is ${raceNumber}.`);
}

else if (!early && age > 18) {
    console.log(`Your race will start at 11:00 and your race number is ${raceNumber}.`);   
}
  
if (age < 18) {
  console.log(`Your race will start at 12:30 and your race number is ${raceNumber}.`);
} 

else {
  console.log(`See registration desk.`);
}

You could change the last else to be
else if (age === 18)
if you only want it to work for those who are exactly 18.

In some cases, you may want to consider using nested if-statements.

if (age > 8) {
  if (early) {
    raceNumber += 1000;
    console.log(`Your race will start at 9:30, your race number is ${raceNumber}.`);
  }
  else {  //(!early) 
    console.log(`Your race will start at 11:00 and your race number is ${raceNumber}.`);
  }

    console.log(`Your race will start at 11:00 and your race number is ${raceNumber}.`);
  }
}
else if (age < 18) {
  console.log(`Your race will start at 12:30 and your race number is ${raceNumber}.`);
}
else {  //(age == 18)
  console.log(`See registration desk.`);
}
1 Like

Thank you so much for your help, I tried that and it worked perfectly! :slight_smile: