Im confused with the function "Switch" any suggestions


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

```

Replace this line with your code.

<do not remove the three backticks above>

#2

What AM I Doing Wrong?

var moonPhase = ‘full’;
switch (moonPhase) {

if (moonPhase === ‘full’ && foggyNight) {
console.log(‘Howwlll!’);
} else if (moonPhase === ‘mostly full’) {
console.log(‘Arms and legs are getting hairier’);
} else if (moonPhase === ‘mostly new’) {
console.log(‘Back on two feet’);
} else {
console.log(‘Invalid moon phase’);
}


#3

you’re mixing the else if and the switch statements. switch is a simpler and easier alternative to the else if statement. So if you use switch then use the corresponding case and break conditions instead of the else if statements. Take a look at the sample code and follow from there.


#4

switch
case;
break;

are useful when you have one or many variables changing their values continuously, and you want to do for every change a different or same action.

The else and else if can get very complex and go out of control


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.