Need help with Sleep Debt Calculator

Hello everyone.

I cant figure out what is wrong with my code. As I see it the code= “console.log(getActualSleepHours());”, should print the sum of the function, but wont. Can you help?

Here’s the code for reference:

const getSleepHours = day => {

switch(day) {

case 'monday':

  return 8

  break;

case 'tuesday':

  return 7

  break;

case 'wednesday':

  return 7

  break;

case 'thursday':

  return 6

  break;

case 'friday':

  return 8

  break;

case 'saturday':

  return 10

  break;

case 'sunday':

  return 7

  break;

default:

  return 'Error!'

}

};

const getActualSleepHours = () => {

getSleepHours(‘monday’) +

getSleepHours(‘tuesday’) +

getSleepHours(‘wednesday’) +

getSleepHours(‘thursdag’) +

getSleepHours(‘friday’) +

getSleepHours(‘saturday’) +

getSleepHours(‘sunday’);

}

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

console.log(getActualSleepHours());

Thank you so much in advance!

You’re missing a very important keyword in getActualSleepHours()

I’m sorry, but I don’t know which keyword you are referring to…

If you want to log the result of a function you need to return something from that function. Also make sure you aren’t misspelling any of the days when you call getSleepHours()

Of course. Now I see it. Thanks so much for your help! (think I should wear my glasses…)

You’re welcome. Learning to debug is just as important as learning to code so look out for those little errors.

1 Like

Hi there, I have a question regarding this as well.

When I print console.log(getActualSleepHours()); it runs as undefined.

Here is my code:

const getSleepHours = (day) => {
switch(day) {
case ‘monday’:
return 6;
break;
case ‘tuesday’:
return 7;
break;
case ‘wednesday’:
return 6;
break;
case ‘thursday’:
return 7;
break;
case ‘friday’:
return 7;
break;
case ‘saturday’:
return 6;
break;
case ‘sunday’:
return 7;
break;
}
}

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

const getIdealSleepHours = () => {
let idealHours = 8;
return idealHours * 7;
}

console.log(getIdealSleepHours());
console.log(getActualSleepHours());

In getActualSleepHours try to use return:

const getActualSleepHours = () => {
return getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesday’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’)
};
1 Like