Sleep Debt Calculator

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hi all

I am very new to JS, just a week.

I am doing this exercise of functions and making a Sleep Debt Calculator. Here is the link https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator.

Here is the code so far, given below. When I logging for getActualSleepHours, I am getting 35Error7. No idea why. Can someone help me please? Thanks

const getSleepHours = day => {

switch (day) {

  case 'monday':

   return 7

   break;

  case 'tuesday' :

   return 7

   break;

  case 'wednesday' :

   return 7

   break;

  case 'thursday' :

   return 7

   break;

  case 'friday' :

   return 7

   break;

  case 'sarturday' :

   return 7

   break;

  case 'sunday' :

   return 7

   break;

  default:

   return 'Error'

  };

};

const getActualSleepHours = ( ) =>

 getSleepHours('monday') +

 getSleepHours('tuesday') +

 getSleepHours('wednesday') +

 getSleepHours('thursday') +

 getSleepHours('friday') +

 getSleepHours('Saturday') +

 getSleepHours('sunday');

 console.log(getActualSleepHours());

you could log the faulty day:

  default:
   console.log(day);
   return 'Error'
  };

that should help?

Thank you. I have tried your solution.

Now its is printing Saturday and 35Error7.

I think I am more confused now.

I only proposed extra logging to help debug. "error" is pretty useless, you have no idea what the error actual is

clearly 'Saturday' does not match with the intended case (case 'sarturday' )

I agree with you. Thanks for your help.

Thanks mate. It worked. After work, cam back home and was trying to study and everything looked crazy. Now it has worked. :slight_smile: