GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 9 von 18 · Medien

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! 

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck