Working on JavaScript Project “Sleep Debt Calculator” and stuck at Step 5. When reviewing the forums of others’ input, I noticed that my structure is slightly different from the majority (I’m not using the ternary function format).
Why does my code fail to work similarly?
My console produces “[Function: getActualSleepHours]” rather than adding up the hours of each day.
See my code below:
function getSleepHours(day) {
switch (day) {
case 'monday': return 8;
case 'tuesday': return 7;
case 'wednesday': return 8;
case 'thursday': return 7;
case 'friday': return 7;
case 'saturday': return 9;
case 'sunday': return 9;
}
};
function getActualSleepHours() {
getSleepHours('monday')
+ getSleepHours('tuesday')
+ getSleepHours('wednesday')
+ getSleepHours('thursday')
+ getSleepHours('friday')
+ getSleepHours('saturday')
+ getSleepHours('sunday');
return getActualSleepHours;
};
console.log(getActualSleepHours());