Day 3: Logic
Lesson 4: If Else
Let's go back to our first example today:
You may have thought at the time:
Isn't it a shame we had to write the case for true and false with
ifboth times 🤷♂️
Well, if you did I have good news. if has a counterpart called else that can handle that false case in the example above. We can rewrite the above as:
I've also removed the === true since happyCoder is already a boolean.
The else { } block doesn't need a condition with ( ) because it will run when the if ( ) condition is false.
if statements don't need an else after them but else statements always need a preceding if - after all, there can't be an else unless there isn't an alternative to begin with!