Build sleep Calculator


#1

I am having trouble finishing this excersise. The error code I’m getting is “actual SleepHours is not defined”??

const getSleepHours = day => {
if (day === “Monday”) {
return 8;
}
else if (day ===“Tuesday”) {
return 8;
}

else if (day === "Wednesday") 	{

return 8;
}
else if (day === “Thursday”) {
return 8;
}
else if (day === “Friday”) {
return 8;
}
else if (day === “Saturday”) {
return 8;
}
else if (day === “Sunday”) {
return 8;
}
};
const getActualSleepHours = () => {
return getSleepHours(‘Monday’) +
getSleepHours(‘Tuesday’) +
getSleepHours(‘Wednesday’) +
getSleepHours(‘Thursday’) +
getSleepHours(‘Friday’) +
getSleepHours(‘Saturday’) +
getSleepHours(‘Sunday’)
}

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

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
}

if (actualSleepHours === idealHours) {
console.log(“You get enough sleep”);
}
else if (actualSleepHours > idealHours) {
console.log(“You get more than enough sleep”);
}
else {
console.log(‘You should get some rest!’);
}
if (actualSleepHours < idealSleepHours) {
console.log(“You got " + idealSleepHours - actualSleepHours + " hours less sleep than you needed this week. Get some rest.”);
}

calculateSleepDebt();

thanks in advance!!


#2

Your if statement should be inside this function where actualSleepHours is defined.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.