Sleep debt calculator

Hello everyone!! I am having issues with the javascript sleep debt calculator. I keep getting syntax error and it keeps doing this:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:10
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)

I have checked my code many times but still can’t figure it out, what amd i doing wrong?
here is my switch statement:

const getSleepHours = day => {
switch(day) {
case ‘monday’:
return 8
break;
case ‘tuesday’:
return 7
break;
case ‘wednesday’
return 8
break;
case ‘thursday’
return 5
break;
case ‘friday’
return 8
break;
case ‘saturday’
return 7
break;
case ‘sunday’
return 8
break;
default:
return “Error”
}
};

console.log (console.log(getSleepHours(‘tuesday’));

2 Likes

That line, and several below it are all missing the required colon on each case clause.

Every break keyword may be safely removed from the switch statement since it is preceded by a return. Anything after return is unreachable; but, that is moot. return OR break.

2 Likes

Thank you for answering so quick! I am still not having any luck for some reason also I am having a bit of hard time understanding what you are saying, if you could provide an example, that would help me out a bunch. so should I remove my break keywords?

2 Likes

Nevermind!! I acutally figured it out. thank you!!!

3 Likes

Whew! I was all set to decipher the post from above and find a way to word it differently. Glad you got through it. Syntax is first and foremost an explicit requirement to pass muster. Can’t compile what we can’t interpret.

My second point had nothing to do with solving this problem. It was technical jargon. Take it as a Nota Bena that stays with you going forward.

2 Likes