# Sleep Debt project

hey, I’ve been recently working on js course, and I got stuck with something wrong happening.
It’s in the sleep debt calculator.
I got all the code pretty fine and OK, I kinda finished. But, when trying to add in the console log for the difference between ideal sleep hours and actual sleep hours, NaN gets logged for the number, and wether its higher or less than hours needed I get the “not enough rest” message. I look all over the code and I don’t understand what’s wrong.

``````const getSleepHours = (day) => {
if (day === "monday") {
return 7.5;
} else if (day === "tuesday") {
return 8;
} else if (day === "wednesday") {
return 9;
} else if (day === "thursday") {
return 9.5;
} else if (day === "friday") {
return 7;
} else if (day === "saturday") {
return 8.5;
} else if (day === "sunday") {
return 10;
} else {
return "Error, not a day.";
}
};

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

const getIdealSleepHours = () => {
let idealHours = 9;
return idealHours * 7;
};

const calculateSleepDebt = () => {
let actualSleepHours = getActualSleepHours;
let idealSleepHours = getIdealSleepHours;
if (actualSleepHours === idealSleepHours) {
console.log("You got the perfect amount of sleep!");
} else if (actualSleepHours > idealSleepHours) {
console.log(
"You sleep too much, you got " +
(actualSleepHours - idealSleepHours) +
"hour(s) more sleep than needed this week."
);
} else if (actualSleepHours < idealSleepHours) {
console.log(
"You should rest, you don't sleep enough. You got " +
(idealSleepHours - actualSleepHours) +
"hour(s) less sleep than needed this week."
);
} else {
console.log("Error");
}
};

calculateSleepDebt(); /*always logging " You should rest, you don't sleep enough.
You got NaNhour(s) less sleep than needed this week."*/

``````

Hi,

The problem is in the calculateSleepDebt function.

When you are writing

``````let actualSleepHours = getActualSleepHours;
let idealSleepHours = getIdealSleepHours;
``````

For both lines, you are not calling the functions but assigning them to new variables.

1 Like

@patmol6 is right. You’re not calling a function in your let expressions, but attempting to assign them values that are not numbers, boolean or a string (it’s not a string because it’s not enclosed in quotes).

That’s where the Not a Number value is coming from.

1 Like

Ohh I see that was that simple, thanks guys!