Switch Statements (Unit Control Flow)


Hi Guys! :slight_smile:
I'm needing help to do the following exercise:

Let's illustrate this by converting our werewolf program to a switch statement. For now, let's also delete the foggyNight variable so it doesn't fog up this concept.

moonPhase will become the condition of the switch statement. Then, each moon phase will become each case that the switch statement checks for.

Start by writing a switch statement with moonPhase as its condition.
Stuck? Get a hint

This is my previous exercise code and I think I should do some alterations on it but I'm really don't understanding.

var moonPhase = 'full';
var foggyNight = false;

if (moonPhase === 'full' && foggyNight) {
} 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');

Explain me what I should do or give me the solved code. :slight_smile:


Hi @luisjesus_2003, here we are not encouraged to provide the solved code directly (depending on how tough the question is) to the new beginners as we want them to try push their limit and try to solve the question with few attempts. Hope you understand.

Do you have any code that you have attempted/tried in that exercise which you can paste here?
We can help point out any mistakes if there's any. :slightly_smiling_face:

Or do you not understand the exercise at all?
I can offer my help to guide you with explanation here, until you got your full answer. :slightly_smiling_face:
(My hint: the answer is not very long)

The exercise requires you to:
1. Make a switch statement.
2. Delete the foggyNight variable
3. Inside the switch statement, insert moonPhase as its condition.
4. You don't need to write the full switch statement yet, just the initial switch statement will do. Make sure the switch syntax is correct.
5. Click the ? Hint in that exercise and you should be able to guess what to do.

Tell me if you're still having problem okay?
Cheers :smiley:


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