Race Day: How does the number assignment work?

Hi everyone, this is my first post on the forum. :man_student:

I was seeking to gain a better understanding of the code behind the Race Day project.

My question is: How does the code know to assign specific individuals who are aged 18+ or younger, but registered late, a race number of under 1000? Since I cannot seem to find or understand the code that allocates this.

Here’s how our registration works. There are adult runners (over 18 years of age) and youth runners (under 18 years of age). They can register early or late. Runners are assigned a race number and start time based on their age and registration.

Race number:

Early adults receive a race number at or above 1000.
All others receive a number below 1000.

I have linked both my code and the project here underneath.

Thanks for any help!

Kind regards,

Brian

Code:

// Race number generation (rN)
let raceNumber = Math.floor(Math.random() * 1000);

// Registration early or late (rE)
const registeredEarly = true;

// Age of runner (rA)
const runnersAge = 22;

// Control and verification of rE & rA = rN
if (registeredEarly && runnersAge > 18) {
  raceNumber += 1000;
} 

// Assignment of rN and time slot

// Early Adults
if (runnersAge > 18 && registeredEarly) {
  console.log(`Your race will begin early, at 09:30. Your assigned race number is ${raceNumber}. Good luck!`);
} // Late Adults
else if (runnersAge > 18 && !registeredEarly) {
  console.log(`Your race will begin late, at 11:00. Your assigned race number is ${raceNumber}. Good luck!`);
} // Youth race
else if (runnersAge < 18) {
  console.log(`Your race will begin at 12:30. Your assigned race race number is ${raceNumber}.`);
}
else { // Failure of assignment
  console.log('Please report to the registration desk for assignment of race number and time slot.');
}

Links:

Project: https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-control-flow/projects/race-day

My code: https://gist.github.com/8dd1cb546469ad6ac374988fd6de4b6a

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

I am confused about your question. You want runners who are over 18 and younger?

1 Like

In the course, runners who are under 18 or who are attending the late race. They are assigned a race number under 1000. Those who are above 18 and are running early, recieve a number above 1000.

Im trying to understand how the code assigns this.

For example Age 22 running late, could have the number 0-999. Age 22 but running early would be a number above 1000. People who are under the age of 18, would also receive a Race number below 1000

I am not sure where your struggles are but lets see.

Ok, so the exercise asks for early registered adults to get a number higher then 1000.

So that means that a person has to qualify for two conditions

Be an adult runnersAge > 18
and
Register early registeredEarly === true

The default number has been set to any number under 1000, so you only need to add 1000 in your code. You have nicely combined those:

// Control and verification of rE & rA = rN
if (registeredEarly && runnersAge > 18) {
  raceNumber += 1000;
} 

This same selection of conditions also qualify for running early so you can combine this with your other if statement.

// Control and verification of rE & rA = rN
if (registeredEarly && runnersAge > 18) {
  raceNumber += 1000;
  console.log(`Your race will begin early, at 09:30. Your assigned race number is ${raceNumber}. Good luck!`);
} 

If you didn’t register late and you are over 18, your number is below 1000 so no need to add to the default number. You still need to check for two conditions

age over 18 runnersAge > 18
and
Registered late registeredEarly === false

You combined those two conditions in your first else if statement.

} else if (runnersAge > 18 && !registeredEarly) {
  console.log(`Your race will begin late, at 11:00. Your assigned race number is ${raceNumber}. Good luck!`);
}

If you are under 18 it does not matter at what time you are registered, you always run at 12.30 so you only need to check for age.

} else if (runnersAge < 18) {
  console.log(`Your race will begin at 12:30. Your assigned race race number is ${raceNumber}.`);
}

Happy coding!

let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = true;
let runnerAge = 20;
if (runnerAge > 18 && registeredEarly){
raceNumber += 1000;
}
if ( runnerAge > 18 && registeredEarly ) {
console.log( Runner ${raceNumber} your race time is 9:30am.);
} else if (runnerAge > 18 && (!registeredEarly)) {
console.log(Runner ${raceNumber} your race time is 11:00am.);
} else if ( runnerAge < 18 && registeredEarly ){
console.log(Runner ${raceNumber} your racetime is 12:30pm.);
} else {
console.log(See the registration desk);
}

this is my code above. incase i want late adult to also get a number above 1000~~ how do i go about it?

The confusion I have is when you add when you add +=1000 to “let raceNumber = Math.floor(Math.random() * 1000)”

Ex: if (registeredEarly && runnersAge > 18) {
raceNumber += 1000;

Does it give you a random number between 1000-1999? or 0-1999?