This project seems easier than the RPS one, as I pretty much managed to complete it by myself. However, I’m stuck with the last task:
For extra practice, try these:
getActualSleepHours()
could be implemented without callinggetSleepHours()
. Use literal numbers and the+
operator to rewritegetActualSleepHours()
. It should still return the total actual hours slept in the week.- Some people need to sleep longer than others. Rewrite
getIdealSleepHours()
so that you can pass it an argument, likegetIdealSleepHours(8)
where8
is the ideal hours per night. Update the call togetIdealSleepHours()
incalculateSleepDebt()
too.
I believe the problems lies in the line, I’ve tried to make “idealHours” a const or let, but it doesn’t help:
const getIdealSleepHours = idealHours => idealHours * 7;
And my whole code looks like that, and for now it return no text nor an error in the console:
const getSleepHours = day => {
if(day === 'monday') {
return 7;
} else if(day === 'tuesday') {
return 7;
} else if(day === 'wednesday'){
return 7;
} else if(day === 'thursday'){
return 7;
} else if(day === 'friday'){
return 7;
} else if(day === 'saturday'){
return 7;
} else if(day === 'sunday'){
return 7;}
};
const getActualSleepHours = () => 7 + 7 + 7 + 7 + 7 + 7 + 7;
const getIdealSleepHours = idealHours => idealHours * 7;
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if(actualSleepHours === idealSleepHours) {
console.log("Congratulations, you sleep perfectly long.");
} else if(actualSleepHours > idealSleepHours){
console.log("You are oversleeping by " + (actualSleepHours-idealSleepHours) + " hours");
} else if(actualSleepHours < idealSleepHours){
console.log("You lack " + (idealSleepHours - actualSleepHours) + " hours of sleep");
}
}
calculateSleepDebt();