5 hands-on exercises and 5 find-the-bug challenges for the JavaScript if Statement lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
If age is 20, show "adult".
If the role is "admin", show "allowed".
If the cart has no items, show "empty".
If the user is logged in AND verified, show "welcome".
Only show the name when it is present; here it is "Sam".
A single = makes this condition always run.
The branches sit on the wrong side of the test, so a 20-year-old is labelled a minor.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceLoose equality lets a string match a number.
A semicolon right after if() ends the statement early.
OR is used where both conditions must hold.