I am just beginning the RaceDay project in the JavaScript section. Could someone help me figure out what I am doing wrong here and why I seem to be getting that error?!
Please find attached a screenshot. Many thanks.
I am just beginning the RaceDay project in the JavaScript section. Could someone help me figure out what I am doing wrong here and why I seem to be getting that error?!
Please find attached a screenshot. Many thanks.
this error is so common, MDN devoted an entire page to it:
Thanks! I feel stupid. It should have been earlyRegister == true
.
google is your friend.
Are you sure you don’t want to use strict/identity equality:
Don’t feel stupid. Just remember Fail is a First Attempt In Learning.
I hope this helps =)
Hi There,
Been scratching my head on this for hours! Can someone please tell me why I am getting a syntax error here?
the semi-colon on line 7 ends the if statement, while it isn’t finished yet
using semi-colons is absolutely recommend, but in the right places
Ahh alleluia! thank you very much for your help with this! Was beginning to go crazy there for a while.
Wow, no kidding. Thank you so much for this!
Hey guys can somebody explain to me why in the projcect walkthrough video we would want to put :
" if ( ageRunner>18 && earlyRunner) { raceNumber += 1000};"
Instead of going ahead and adding 1000 to raceNumber as I did below? TIA
let raceNumber = Math.floor(Math.random() * 1000);
const earlyRunner = true;
const ageRunner = 18;
if (earlyRunner && ageRunner > 18) {
console.log(
You are racing at 9:30 am, and ${raceNumber + 1000} is your number
);
} else if (!earlyRunner && ageRunner > 18) {
console.log(You are racing at 11:00 am, and ${raceNumber} is your number
);
} else if (ageRunner < 18) {
console.log(You are racing at 12:30 pm, and ${raceNumber} is your number
);
} else {console.log(‘Please proceed to the registration desk where our staff will give you further details about your registration.’)}
Not sure if I’m following the proper instructions as when I check the AI hint, it tells me I’m wrong.
Can someone please clarify?
Create a separate control flow statement below the first (starting with if
again). This statement will check age and registration time to determine race time.
For runners over 18 who registered early, log a statement to the console telling them that they will race at 9:30 am. Include their raceNumber
.
AI-generated hint
1 of 3
It looks like the code is on the right track. However, you have two separate if statements that check the same conditions. In order to satisfy task 5, you need to merge these two if statements into one. Remember, the if statement should check if the runner is over 18 and registered early. If that condition is true, you should log the statement to the console. Give it a try and see if you can consolidate the code into a single if statement.
let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = true;
let runnersAge = 19;
if (runnersAge > 18 && registeredEarly) {
console.log(raceNumber);
}
if (runnersAge > 18 && registeredEarly) {
console.log(You\'re race start time will be 9:30am and your race number is ${raceNumber}.
);
}
Sorry, now I’m getting another conflicting statement from the AI generator.
Please help.
AI-generated hint
3 of 3
Your code correctly checks whether the runner is an adult and registered early. However, you need to add an else if statement to handle the case of late adults. Within that statement, log a string to the console telling them that they will race at 11:00am and include their raceNumber.
You can use the following example code as a guide to help you complete this task:
else if (runnersAge > 18 && !registeredEarly) {
console.log(Your race time will be at 11:00am and your race number is ${raceNumber}.
);
}
Once you’ve added this else if statement, test your code with different combinations of values for the variables to make sure it’s working correctly.
Powered by
My code
let raceNumber = Math.floor(Math.random() * 1000);
let registeredEarly = true;
let runnersAge = 19;
if (runnersAge > 18 && registeredEarly) {
console.log(raceNumber);
}
if (runnersAge > 18 && registeredEarly) {
console.log(You\'re race start time will be 9:30am and your race number is ${raceNumber}.
)
} else if (runnersAge > 18 && !registeredEarly) {
console.log(You\'re race time will be at 11:00am and your race number is ${raceNumber}.
);
}