Javascript error, why it gives me less than 1000?

code:

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

let regEarly=true;

let runAge=28

let regNumber=''

let runTime=''

if (regEarly && runAge > 18) {

  regNumber= raceNumber+1000

} else (regEarly === false || runAge < 18); {

  regNumber= raceNumber

}

console.log(`Your number is ${regNumber}. Good luck`);

exercise:
Learn JavaScript Syntax: Conditionals | Codecademy

ELSE is the default. For the above we need to include the if keyword.

Note the semicolon in your code. That will interrupt the statement and not parse futher. The statement contained in the block will execute no matter what. Lesson here, never use semi-colons in if statements.

if (conditionOne) {

} else if (conditionTwo) {

} else {

}

The statements inside the blocks may require semi-colons. The above construct has none, ever.

Thanks for the advice! it worked :slight_smile:
now my code is:
let raceNumber = Math.floor(Math.random() * 1000);
let regEarly=true;
let runAge=19
let regNumber=’’
let runTime=’’
if (regEarly && runAge >= 18) {
regNumber= ${raceNumber + 1000} and you will run at 09:30
} else if (!regEarly && runAge >= 18) {
regNumber= ${raceNumber} and you will run at 11:00
} else if (runAge<18) {
regNumber= ${raceNumber} and you will run at 12:30
}
console.log(Your number is ${regNumber}. Good luck!);

1 Like