Skip to content
dreamcode
dreamcode
Map
Else If
Lesson 8 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 2 · JS Conditionals & Logic

Else If Chains

Check multiple conditions using else if blocks. JavaScript runs the first block where the condition evaluates to true and skips the rest.

Worked example

How it reads

  • else if (hour < 18) runs only if the preceding if statement was false
  • The final else runs if no conditions were met
Cloud tip: You can insert as many else if blocks as necessary between the initial if and the final else.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add another else if so 50 to 79 percent logs Mostly Cloudy, then set cloudPercent to 65 to see it.

Press Run to check your work.