Sleep debt calculator - Syntax error

Hey,

I’m currently try to work through the sleep debt calc exercise in JS.

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/sleep-debt-calculator

I can’t seem to find why I get a syntax error when logging the following code:

const getSleepHours = day => {
 
  switch(day) {
    case 'monday':
      return 8
      break;
    case 'tuesday':
      return 7
      break;
    case 'wednesday':
      return 8
      break;
    case 'thursday'
      return 8
      break;
    case 'friday'
      return 9
      break;
    case 'saturday'
      return 7
      break;
    case 'sunday'
      return 7
      break;
   
    default:
      return "Error!"
      
  }
};

console.log(getSleepHours('monday'))
  return 8
      ^^^^^^
SyntaxError: Unexpected token return
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)

Hello :slight_smile: I formatted your code. Open the edit mode and see how to do that in the future posts.

This part of the code is correct:

    case 'wednesday':
      return 8
      break;

This part of the code is incorrect:

      case 'thursday'
      return 8
      break;

What is the difference?

4 Likes