Sleep Debt Calculator

Hello,

I am having some trouble with the sleep debt calculator. At the end of the code, the console should type 35 however it types 8765432 and I have no idea why. The code is the same as in the tutorial but I still cant get it to work.

Any idea why?

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

const getSleepHours = day => {

switch (day) {
case ‘Monday’:
return ‘8’;
break;
case ‘Tuesday’:
return ‘7’;
break;
case ‘Wednesday’:
return ‘6’;
break;
case ‘Thursday’:
return ‘5’;
break;
case ‘Friday’:
return ‘4’;
break;
case ‘Saturday’:
return ‘3’;
break;
case ‘Sunday’:
return ‘2’;
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());

Nevermind, I managed to get it to work. The ’ near the numbers was the problem. :stuck_out_tongue:

1 Like

Yeah, you had the numbers as strings, so the +'s were just concatenating rather than adding them. Nice quick solve!

1 Like