Sleep debt calculator: I am getting a huge number of hours: 146.576.568

I checked my code several times with the video, and up to step 6 it looks the same. However my total number of actualSleepHours is over 146 millions! Can anyone help?
const getSleepHours = day => {
switch (day) {
case ‘Monday’:
return 8
break;
case ‘Tuesday’:
return 6
break;
case ‘Wednesday’:
return ‘6.5’
break;
case ‘Thursday’:
return 7
break;
case ‘Friday’:
return ‘6.5’
break;
case ‘Saturday’:
return ‘6’
break;
case ‘Sunday’:
return 8
break;
default:
return ‘Invalid day entry!’
}
};

const getActualSleepHours = () =>
getSleepHours(‘Monday’) + getSleepHours(‘Tuesday’) + getSleepHours(‘Wednesday’) + getSleepHours(‘Thursday’) + getSleepHours(‘Friday’) + getSleepHours(‘Saturday’) + getSleepHours(‘Sunday’) ;

console.log(getActualSleepHours());

Ok, I figured out that if I don’t try to use decimals in the hours it works. But I do not understand what the problem with those decimals is.

Hello @gigaslayer88599, welcome to the forums! The reason is your getSleepHours function returns strings for some values:

Being an example.

Thanks! When I took out the single quotes it worked. For some reason I thought I had to use them for numbers that contain decimals. Learned the hard way! :slight_smile:

1 Like