Newbie Question!

Hello Everybody!

I have simple question. Based on how I’m interpreting this, the answer should be the third statement with a number under 1000 since the age of the runner is > 18. However when I log the statement it is still giving me a value of over 1000 for the raceNumber. Why is it that when the condition is not being met that it is still adding 1000 to the race number.

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

let early = true;
let age = 15;

if (early && age > 18); {
raceNumber += 1000;

if (early && age > 18){
console.log(The race starts at 9:30am. Your race number is: ${raceNumber});
} else if (!early && age > 18) {
console.log(The race starts at 11:00am. Your race number is: ${raceNumber});
}else if (age < 18) {
console.log( The race starts at 12:30pm. Your race number is ${raceNumber});

Hello @nickarredondo8714205 ,

Try putting a console.log for your raceNumber before your if statements to verify the value.

Hey @coffeencake

Thanks you for responding. Your response helped me figure out that the problem lied within the “if” statement

Initial Code
if (early && age > 18); {
raceNumber += 1000;

Correct Code
if(early && age > 18) {
raceNumber += 1000;

In the first code I had placed and extra “;” after the condition which added the 1000 to every number. Without the extra semicolon it ran the code correct.

Thank you!


1 Like