What is wrong with my code : 7. switch Statements


var moonPhase = ‘mostly full’
switch(moonPhase){case’full’:console.log(‘Howwwwlll!!’);break; case’mostly full’:console.log(‘Arms and legs are getting hairier’);break; case’mostly new’:console.log(‘Back on two feet’);break: console.log(‘Invalid moon phase’);break}


That needs to be the default case:

    default: console.log(‘Invalid moon phase’);


Let’s start with how you layout code. You want to make it as clear and readable as possible. Formatting matters, as it directly impacts how easy it is to read your code (for you and anyone else who reads it).

Let’s reformat your code as is. I added a few comments to point out the problem areas:

var moonPhase = 'mostly full' // <- 1. Missing the semicolon

switch (moonPhase) {
        console.log('Howwwwlll!!'); // <- 2. problem with string literal
    case'mostly full':
        console.log('Arms and legs are getting hairier');
    case'mostly new':
        console.log('Back on two feet');
        break // <- 1. Missing the semicolon
    : // 3. what's missing here?
        console.log('Invalid moon phase');


  1. Missing semicolons at the end of a couple of lines of code.
  2. Check instruction 2. Notice that when the moon phase is 'full', you should be printing out 'Howl! and not Howwwwlll!!.

If moonPhase is 'full', then use console.log() to print Howl!

  1. Look at the last switch level. You have just a colon and nothing else. What’s missing? Look at Instruction 3:

Now, add a default at the end of the switch that uses console.log() to print Invalid moon phase, in the case that moonPhase does not equal one of our cases.


Thank you @mtf finally it worked


Thank you @hellofromtonya you are heaven sent!


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