SleepDebtCalculator

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-functions/projects/sleep-debt-calculator

Hey everyone,

I am currently working on the sleep debt calculator project and am getting stuck on step
5.Inside the getActualSleepHours() function, call the getSleepHours() function for each day of the week. Add the results together and return the sum using an implicit return .

const getSleepHours = day => {

switch(day) {
case ‘monday’:
return 8
break;
case ‘tuesday’:
return 7
break;
case ‘wednesday’:
return 8
break;
case ‘thursday’:
return 9
break;
case ‘friday’:
return 6
break;
case ‘saturday’:
return 7
break;
case ‘sunday’:
return 8
break;
default :
return “Error!”
}
};

const getActualSleepHours = () => getSleepHours(‘monday’) + getSleepHours(‘tuseday’) + getSleepHours(‘wednesday’) +
getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);

This is the code I wrote corresponding to that step. It matches that of the video guide as well. However I keep receiving an error that reads 8Error!89678
Can anyone help me and point out my error? Thank you for any help!

1 Like

Hey!

Did you copy and paste this code? It might just be a syntax error - I noticed that Tuesday is misspelled in your getActualSleepHours() function. Does fixing that help?

edit: I’m also noticing that in your switch statement, you should include a semi-colon after your returns.

ex.

switch(day) {
 case ‘monday’:
  return 8;
  break;
 ...
}
1 Like

welp, I stared at it for 30 mins and couldn’t see that! thanks :sweat_smile:
that did correct the error

1 Like

thank you! it ran without the semi colons so I am wondering if they are necessary?

ahah It’s happened to me a billion times! You’re welcome!

They might not be necessary here - I think its because you don’t need semicolons after a statement, but it can be considered good practice. I didn’t know that the code would run without them, so I looked it up and found this Codecademy article :stuck_out_tongue:

1 Like

Hi @laurasuriani21732830 - I would really appreciate it if you would mark this topic as solved when you get a second. Thank you!

1 Like