Output

Hello - Can you please take a look at the below code. Race number is not bringing out the right out.

let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = true;
let runnersAge = 18;
if(registeredEarly && runnersAge > 18)
{
raceNumber += 1000;
}
if(registeredEarly && runnersAge > 18){
console.log(‘Race will begin at 9:30am, your race number is: ${raceNumber}.’)
}

else if(!registeredEarly && runnersAge >18){
console.log(‘Race will begin at 11:00am,your race number is: ${raceNumber}.’)
}
else if(runnersAge < 18){
console.log(‘Race will begin at 12:30pm,your race number is: ${raceNumber}.’)
}
else {
console.log(‘Approach the registration desk, thanks!’)
}

What output are you currently getting, and how is that different to your desired output?


In the console.log() functions, it appears you’re trying to use a template literal. Note, when using template literals, you must use back ticks( ``` ), not quotation marks (""):

let someVar = "Hi";
console.log("${someVar} World!");
//logs ${someVar} World!
console.log(`${someVar} World!`);
//logs Hi World!
1 Like

Thank you, instead of getting a random number for raceNumber the output comes out as ${raceNumber). I.e. Race will begin at 11:00 am,your race number is: ${raceNumber}

Yes, then sounds your issue is what codeneutrino describes. Make sure you are using the backtick symbols ` (top left corner on your keyboard) for template literal text outputs.

2 Likes

Thank you both…Really helpful

1 Like