Sleep Debt Calculator

I need help with Step 2/3 in calculating the hrs of sleep in the sleep debt calculator. When i use the switch statement of this code but then test it i keep getting an error message. I used the ‘getunstuck’ help video but i am having no luck.

check your spelling (the switch statement itself and one weekday).

1 Like

i looked over the code and you were right about the spelling parts. After i changed them i didn’t get the error codes anymore but when i put the console.log in the code to get the number of hours of sleep based on the day, nothing showed up. it was blank. I’m not sure what i am doing wrong

Could you then paste your current code here, please? Please make sure to format it (Mark your code and press </>).

I am new to all of this how would i mark it. Do i put </> at the end or beginning of the copied code?

Paste your code into this window, then mark it, then press </> (the key in the editor → right symbol in screenshot).
Bildschirmfoto 2023-01-07 um 21.21.13

const getSleepHours = day => {
  switch(day) {

    case 'monday':
    return 8
    case 'tuesday':
    return 7
    case 'wednesday':
    return 8
    case 'thursday':
    return 5
    case 'friday' :
    return 8
    case 'saturday':
    return 7
    case 'sunday':
    return 8
      return "Error!"


const getActualSleepHours = () => 
  getSleepHours('monday') +
  getSleepHours('tueday') +
  getSleepHours('wednesday') +
  getSleepHours('thursday') +
  getSleepHours('friday') +
  getSleepHours('saturday') +


i hope i did it right

Another spelling mistake. getSleepHours('tueday') is undefined.
Your console.log() in the switch statement should be removed. Nothing after the return keyword is executed. And if it were, it would throw an error.

Yes. The format is fine.

1 Like

i made the changes and everything worked out. thank you for looking over my code. I have to get better at reviewing my code before i try to execute it.

1 Like

Let the console help you. Most of the mistakes you made are pointed out by the error messages in the console. Interpreting the error messages rather than reading your code saves a lot of time.

i will definitely remember to do that. i think i rushed to see how i could fix the problem and didn’t take the time to see what the console was describing. I am going to try to not make that mistake again.

1 Like

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