0PricingLogin
Javascript for Kids · Lesson

Plan B with else

Do something different when it is false.

Plan B with else 🅱️

Hi, clever coder! 🌟 What if the rule is NOT true? We need a Plan B!

We use the magic word else for "otherwise, do THIS". 🪄

if (false) {
  console.log("Plan A")
} else {
  console.log("Plan B! 🅱️")
}

If This, Else That 🔀

else always comes right after an if.

If the rule is true, do the first part. Otherwise, do the else part! 🚪🚪

if (true) {
  console.log("Door A 🚪")
} else {
  console.log("Door B 🚪")
}

All lessons in this course

  1. Making a Choice with if
  2. Plan B with else
  3. Comparing Things
  4. More Choices with else if
← Back to Javascript for Kids