Sleep Debt Calculator Idea

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

The answer for the actual sleep hours I got is

8787968

instead of

54(total)

Can anymore tell me the problem of the following code I input, thank you !

const getSleepHours = (day) => {
switch (day){
case ‘mon’:
return ‘8’;
break;
case ‘tue’:
return ‘7’;
break;
case ‘wed’:
return ‘8’;
break;
case ‘thu’:
return ‘7’;
break;
case ‘fri’:
return ‘9’;
break;
case ‘sat’:
return ‘6’;
break;
case ‘sun’:
return ‘8’;
}
};

console.log(getSleepHours(‘mon’))

const getActualSleepHours = () =>
getSleepHours(‘mon’) +
getSleepHours(‘tue’) +
getSleepHours(‘wed’) +
getSleepHours(‘thu’) +
getSleepHours(‘fri’) +
getSleepHours(‘sat’) +
getSleepHours(‘sun’);

console.log(getActualSleepHours());

Hello, and welcome to the forums!

Since your getSleepHours() function is returning strings instead of numbers, when you “add” them together in getActualSleepHours, you are really concatenating the strings. Take a closer look at the return values in getSleepHours

2 Likes