GoConqr has a new look! Let us know what you think.

Module 9 of 18 · Media

Checking multiple if cases

Kostas Diakogiannis

Checking multiple if cases

Checking multiple cases

What if we want to check more than one cases. Take a look at the sample code above. There we have defined a variable that represents the favorite color of a user (cyan for now), and based on that we want to print to the console a relevant band. 

So if user's favorite color is red, then we give back 'Red Hot Chilli Peppers'.

If is green, we print 'Green Day'

if purple, 'Deep Purple'

Otherwise if none of that we give back 'Black Sabbath'.

Each if (or else if) statements is checked sequentially, the first statement's condition that evaluates to true, executes the following block. Then ALL the following blocks, are ignored! 

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?