# Sleep Debt Calculator Exercise

Here is the code I have so far:

let getSleepHours = (day) => {
if (day === ‘monday’){
return ‘8’;
} else if (day === ‘tuesday’){
return ‘7’;
} else if (day === ‘wednesday’){
return ‘8’;
} else if (day === ‘thursday’){
return ‘8’;
} else if (day === ‘friday’){
return ‘9’;
} else if (day === ‘saturday’){
return ‘7’;
} else if (day === ‘sunday’){
return ‘8’;
}
};

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

console.log(getActualSleepHours());

Why do the results for each day of the week get concatenated instead of added? The result I get is 8788978, and I cannot figure out why they will not add. If I insert any operator other than a plus sign, the math works.

Because you return strings, not numbers…

2 Likes

Ahhh, thank you! That makes sense.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.