[SleepDebt Project] results of function call do not add to a sum

I’m currently working on the SleepDebt Project in Intruduction to JS and am currently stuck on adding up the hours of sleep with an implicit return.

When I log it to the console, the numbers are not adding up but are just displayed on after the other. I cannot figure out why they are not adding. Please help?

const getSleepHours = day => {
  switch (day) {
   case 'monday':
     return '8';
     break;
   case 'tuesday':
     return '7';
      break;
   case 'wednesday':
     return '7';
      break;
   case 'thursday':
     return '4';
      break;
   case 'friday':
     return '6';
      break;
   case 'saturday':
     return '9';
      break;
   case 'sunday':
     return '9';
      break;
   default: 
     return 'Error'
  }
};

const getActualSleepHours = () => 
getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours ('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday');



console.log(getSleepHours('monday'));
console.log(getActualSleepHours());

If you want to concatenate strings, you use strings:

console.log('6' + '5'); //65

If you want to add numbers, you use numbers:

console.log(6 + 5); //11

There’s also no need for break following a return statement. return hands a value, and sends control flow back to the caller. The break statements are never executed. If Mr. Smith sent you to my office to retrieve a document, and I hand you the document, and say, “Take this back to Mr. Smith.” There would be no need after you’ve left for me to say, “Leave my office.”

1 Like

Thanks so much! It’s always the little things that get me. Hopefully I will get better with practice, less potential for frustration!

2 Likes

Undoubtedly, you will. Happy coding!

2 Likes