Hello! I just completed my assignment on Javascript conditionals. The code works perfectly and I was wondering if there could be a way I can assign a Race Number to each participant without having the same number repeat itself

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

const early = true;

const age = 18;

if (age > 18 && early || !early) {

raceNumber += 1000;

} //I used the || (OR) condition in my if statement because the code will return a raceNumber less than 1000 if an adult showed up late to the race although only early adults are supposed to receive a race number above 1000, I was just playing around to see what is possible with Java Script :slight_smile:

if (age > 18 && early) {

console.log(Welcome! Your race is by 9:30 am and your Race Number is ${raceNumber}.);

} else if (age > 18 && !early) {

console.log(Welcome! Your race is by 11:00 am and your Race Number is ${raceNumber}.);

} else if (age < 18) {

console.log(Welcome! Your race is by 12:30 pm and your Race Number is ${raceNumber}.);

} else {

console.log(β€˜See the registeration desk.’)

}Preformatted text

Keep a variable representing a unique id (integer is fine for this case). Every time a number is assigned, increase the integer by 1.

Later you can keep these in a database and just keep track of the max id number.

At least in simple scenarios this is fine, you have to get a bit more thoughtful if you’re thinking of larger data sets.

1 Like

Thank you so much for your response.