Stuck on raceday project, not sure how to complete this code


#1

not sure how to complete the code, the project is supposed to take in the runners age, registration status and give them a race number and time depending on the conditions and print it to the console.log.

im doing something wrong but not sure what and how to correct it.



var signedLate = true;
var runnersAge = 18;
let raceNumber = Math.floor(Math.random()*1000);

if(signedLate === true){
  raceNumber += 1000;}

if(raceNumber < 1000 && runnersAge > 18){
  console.log("you will race at 9:30 am with the number ${raceNumber}");
} else if(raceNumber < 1000 || runnersAge > 18){
  console.log("you will race at 11 pm with the number ${raceNumber}");
} else if(raceNumber >= 1000 && runnersAge < 18) {
  console.log("you will race at 12.30 pm with the number ${raceNumber}");
} else {
  console.log("please see registration desk")
}


edit - 5 mins later and refreshing the page and it started displaying. yay


#2

This is my code. Maybe it help’s you. My code is working.
There are only some little changes to your code.
Among others in JavaScript ES6 backticks (`) and${} are used to interpolate values into a string.
You have quotes.

var signedEarly = false;
var runnersAge = 15;
let raceNumber = Math.floor(Math.random()*1000);

if(signedEarly === false){
raceNumber += 1000;}

if(runnersAge > 18 && signedEarly === true){
console.log(you will race at 9:30 am with the number ${raceNumber});
} else if(signedEarly === true|| runnersAge > 18){
console.log(you will race at 11 pm with the number ${raceNumber});
} else if(signedEarly === false && runnersAge <= 18) {
console.log(you will race at 12.30 pm with the number ${raceNumber});
} else {
console.log(“please see registration desk”)
}


#3
  1. I think to use the ${…}, you need to use backslashes rather than quotes. So it would be:
    console.log(``you will race at 9:30 am with the number ${raceNumber}`);

(ignore the repetition of the opening backslash. Just use one at the beginning and one at the end)

  1. Also I think you meant to write:
    if(raceNumber < 1000 && runnersAge < 18){ …

I hope this helps.


#4

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