Click here to navigate the course.

Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor

if/else statements are either this or that for us right now. They answer questions that are either yes or no.

What can we do if we have a question that has multiple yes conditions, or multiple no conditions?

We can add more conditions to our if/else statement with: else if. Check out how this fits into our current knowledge of if/else statements:

var stopLight = 'green'; if (stopLight === 'red') { console.log('Stop'); } else if (stopLight === 'yellow') { console.log('Slow down'); } else if (stopLight === 'green') { console.log('Go!'); } else { console.log('Caution, unknown!'); }

1. We created a variable named stopLight that is assigned to the String 'green'.

2. Then, there's an if/else statement with multiple conditions, using else if. else if allows us to find multiple states of the stopLight variable, and output different things based on its color.

3. The whole thing ends with the singular else we know and love. The else is a catch-all for any other situation. For instance, if the stopLight was blinking blue, the last else would catch it and return a default message.

report a_bug
If you see a bug or any other issue with this page, please report it here.