If else works don't work. Please show me how to fix

Hi guys!
I’m studying Basic Javascript and doing small project provided by Codecademy. My works complete and no error, but when I try “registerEarly= true”, I respect the print will be “ticket type: late register”.

I don’t know why it don’t work. Please anyone can help me.

let raceNumber = Math.floor(Math.random() * 1000);
var registerEarly =true;
var age = 20;
var startTime;
var ticketType='';

if (registerEarly=true){ticketType='early register';}{ticketType='late register'};

if (age>=18 && registerEarly===true) {
  raceNumber+=1000; startTime='09:30 am'
  } else if (age>=18 && registerEarly===false) {
  raceNumber+=1000; startTime='11:00 am'
} else { raceNumber-=100; startTime = '12:30 am'}

console.log(`Age ${age} ; Racing Number ${raceNumber}, Ticket type ${ticketType} ; start time ${startTime}`);

Hey there,




are not the same thing. Which one should you be using?


In addition to ghostlovescore’s comment, there’s also a problem with the first “if” statement.

if (registerEarly=true){ticketType='early register';}{ticketType='late register'};

You’ve got an if / else condition here, but only an “if” in the code. You need to add the “else” for the second condition. Fix that and the problem addressed above and the code should run correctly

1 Like

You have a problem in if statement syntax , you should write it like this :

if (registerEarly === true)
{ticketType = ‘early register’;} else {ticketType = ‘late register’};

Just to add:

The single ‘=’ is used to set a value (the left hand side will become equal the right hand side) whereas ‘===’ is used to compare two values

1 Like