Race Day Exercise, order of elements in if statement

Hi folks, quick question about something that came up in the Race Day Javascript exercise. Point 4 asks us to:

“Create a control flow statement that checks whether the runner is an adult AND registered early. Add 1000 to their raceNumber if this is true.”

My question is about the order of the elements. Why does this work:

if (registeredEarly = true && runnerAge > 18) {
raceNumber += 1000;

But reordering it to put runnerAge > 18 first, as follows, does not:

if (runnerAge > 18 && registeredEarly = true) {
raceNumber += 1000;

The error message in the second case is ‘Invalid left-hand side in assignment’. I’m guessing there is some issue with the syntax in that one type of element must come before the other, but I don’t understand what it is or why. If someone could explain this I’d be very grateful!

I’m unsure why that wouldn’t work, but I do see an error in your code above with the equality operator.

if(hello = hello){ } //Is not the same as if(hello == hello){ }

The first is an assignment, the second is an equality operator.