This code isnt working properly

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

const registeredEarly = false;

const age = 18;

if(age =>18 && registeredEarly === true){

raceNumber+=1000;

console.log(‘Race will start at 9.30 am Your race number is :’+ raceNumber)

}

else if(age => 18 && registeredEarly === false) {

console.log('Race will start at 11.00 am Your race number is : '+ raceNumber)

}

else{

console.log(‘Youth registrants run at 12:30 pm Your race number is :’+ raceNumber)

}
i dont know what is the problem here.
Middle condition supposed to be work but instead of middle, first condition works help me plz

If your if conditions here, you’ve got it written as age => 18 however this is changing the whole if condition into essentially a function, which is by default truthy, and hence it’s basically saying:

if(true){

   raceNumber+=1000;
   console.log(‘Race will start at 9.30 am Your race number is :’+ raceNumber)

}

which is why it’ll always evaluate. When you are wanting ‘greater than or equal to’, you want to write it in the code in that order also, so ‘greater than or equal to’ becomes >=, as in JS => defines an arrow function.

Just wanted to add that the logical operator === true is unnecessary when evaluating a boolean value. In other words, registeredEarly already carries the values “true” or “false”, you don’t have to provide the === true or === false to get it to evaluate to true or false – it’s like asking “if the truth is true…”. The conditional statements could look like this:

if (age >= 18 && registeredEarly) {

} else if (age >= 18 && !registeredEarly) {

It looks cleaner and is more human-readable!