Howdy All,
The SleepDebt project works well until Task 12 bullet point 2 is substituted with the code contained in the “Get a Hint” section.
At the end of my code, there are 3 console.log outputs:
1/ Message generated by actual sleep compared to ideal sleep.
2/ Number of actual sleep hours.
3/ Number of ideal sleep hours.
Before the Task 12.2 substitution the outputs are:
“You have the perfect amount of sleep”
“56”
“56”
After the Task 12.2 substitution the outputs are:
“You have the perfect amount of sleep”
“56”
“NaN”
Please, can anyone see the error of my code and explain why this is happening?
Thank you kindly
const getSleepHours = day => {
day = day.toLowerCase();
switch(day){
case ‘monday’:
return 8
break;
case ‘tuesday’:
return 8
break;
case ‘wednesday’:
return 8
break;
case ‘thursday’:
return 8
break;
case ‘friday’:
return 7
break;
case ‘saturday’:
return 8
break;
case ‘sunday’:
return 8
break;
default:
return "Error!, please enter a day of the week."
}
};
const getActualSleepHours = () =>
8 + 8 + 8 + 8 + 8 + 8 + 8;
// above & below are alternative input styles
/*
getSleepHours(‘monday’) +
getSleepHours(‘tuesday’) +
getSleepHours(‘wednesday’) +
getSleepHours(‘thursday’) +
getSleepHours(‘friday’) +
getSleepHours(‘saturday’) +
getSleepHours(‘sunday’);
/
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours * 7;
};
/
// version2 of getIdealSleepHours
const getIdealSleepHours = idealHours => idealHours * 7;
}
*/
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours(8);
if (actualSleepHours === idealSleepHours)
{
console.log(“You have the perfect amount of sleep.”);
} else if (idealSleepHours > actualSleepHours)
{
console.log(You need
- (idealSleepHours - actualSleepHours)
-
hour(s) more rest each week.
);
}else if (idealSleepHours < actualSleepHours)
{
console.log(“You are well rested.”);
}
else{
console.log(“Check your code”)
}
};
calculateSleepDebt();
console.log(getActualSleepHours());
console.log(getIdealSleepHours());