Need some more insight


#1

Hey, so i need a little help on the raceday project. The aim of it is to take a runner’s Age and registration status and give them a number and a time for their race.

So the code i wrote worked okay but i want to ensure that every runner gets a different race number i.e that no two runners have the same number. How can i do that please? Any help would be appreciated.

This is the code



//raceday project. The code should take a runner's age and registration status and give them a number and a time for the race.

let registeredEarly = false
let raceNumber = Math.floor(Math.random() * 1000)
let runnersAge = 17
if(registeredEarly === false){
  raceNumber += 1000;
}
if (registeredEarly === true && runnersAge <= 18) {
  console.log('Your race number is '+ raceNumber + ' and your race is at 9:30am')
} else if (registeredEarly === false && runnersAge <= 18) {
  console.log('Your race number is '+ raceNumber + ' and your race is at 3:00pm')
} else if (runnersAge > 18) {
  console.log('Your race number is '+ raceNumber + ' and your race is at 11:00pm')
} else {
  console.log('If you are unsure of your registration status, please see the registration desk')
}




#2

this program currently only hands out a single race number?

you would need to make a loop so you give away multiply race/start numbers, then you can use an array to store the numbers you gave away, and use .includes() to verify you didn’t already gave away a certain race/start number


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.