if (day === "Monday") {
return 8;
} else if (day === "Tuesday") {
return 7;
} else if (day === "Wednessday") {
return 6;
} else if (day === "Thursday") {
return 7;
} else if (day === "Friday") {
return 8;
} else if (day === "Saturday") {
return 8;
} else if (day === "Sunday") {
return 5;
} else {
return "Error";
}
};
console.log(getSleepHours("Wednessday"));
const getActualSleepHours = () =>
getSleepHours("Monday") +
getSleepHours("Tuesday") +
getSleepHours("Wednessday") +
getSleepHours("Thursday") +
getSleepHours("Friday") +
getSleepHours("Saturday") +
getSleepHours("Sunday");
console.log(getActualSleepHours());
const getIdealSleepHours = () => {
let idealHours = 8;
return idealHours * 7;
};
// const getIdealSleepHours = idealHours => idealHours * 7;
console.log(getIdealSleepHours());
const calculateSleepDebt = () => {
let actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
// const idealSleepHours = getIdealSleepHours(8);
if ((actualSleepHours = idealSleepHours)) {
console.log("You got the perfect amount of sleep!.");
} else if (actualSleepHours > idealSleepHours) {
console.log(
"You got " +
(actualSleepHours - idealSleepHours) +
"more sleep than needed!."
);
} else if (actualSleepHours < idealSleepHours) {
console.log(
"You need to get some rest because you've slept" +
(idealSleepHours - actualSleepHours) +
"less this week!."
);
} else {
console.log("Something went wrong!.");
}
};
calculateSleepDebt();
Hi, every time I save my code, it keeps giving the same answer of user getting perfect sleep even after I change my return values. I guess something is not right in my else if statements, but i’ve been trying to find the error for over an hour. I would really appreciate the help!.
https://www.codecademy.com/workspaces/63ee6eeb42de2c28e67c13b6
I was also getting an error of assigning to a constant variable in the calculateSleepDebt, but i changed from const to let and it worked, but when i watched the walkthrough video, Galina’s code ran on the const variable.
p.s - the code in comments are my attempts of step 12 which is also giving and error message.