Help with my project (sleep debt calculator)

Hi everyone,

I’m getting stuck on my project and not sure what’s wrong. Any help would be appreciated. I have the following code:

const getSleepHours = day => {

 switch(day) {

 case 'monday':

 return 8

 break;

 case 'tuesday':

 return 6

 break;

 case 'wednesday':

 return 7

 break;

 case 'thursday':

 return 8

 break;

 case 'friday':

 return 10

 break; 

 case 'saturday':

 return 6

 break;

 case 'sunday':

 return 8

 break;

 default: 

 return "error"

}

console.log(getSleepHours('monday'));

};

But nothing appears when I run the program despite having console.log in there.

Thanks in advance!

Link to project: https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator

Notice how the console.log() statement is still within the function:

That means you’re trying to print the function’s output from within the function. Also, since the console.log() comes after a return statement (there’s no way that something won’t be returned from the switch block), it will never run, as return ends the function.

I hope this helps!

Thank you! Ok, so I moved the console.log out of the function but I don’t quite get what you mean about it coming after the return statement.

If you look at the switch block, every possible value of day leads to a return statement. Because return ends the function-no code after it is executed:

function x(){
  console.log("This will print");
  return "This ends the function";
  console.log("This will not print");
}

The console.log() will never run…