https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator
Hi, I am halfway through my project and it seems when I go to run my code it logs to the console the entire getActualSleepHours
function as a string concatenated with the string I already have written in the console log instead of concatenating the string with the number the function should evaluate to, and I can’t figure out why. Here is my full code, as I am not sure exactly where the problem is:
const getSleepHours = day => {
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 8;
break;
case 'saturday':
return 8;
break;
case 'sunday':
return 8;
break;
default:
return "Error!"
}
};
const getActualSleepHours = () =>
getSleepHours('monday')
+ getSleepHours('tuesday')
+ getSleepHours('wednesday')
+ getSleepHours('thursday')
+ getSleepHours('friday')
+ getSleepHours('saturday')
+ getSleepHours('sunday');
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours * 7;
}
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log("You got " + (getActualSleepHours) + ", which is the perfect amount of sleep! Good job!");
} else if (actualSleepHours > idealSleepHours) {
console.log("You slept more than your goal of " + (idealSleepHours) + " hour(s) by exactly: " + (actualSleepHours - idealSleepHours) + " hour(s). Remember, too much sleep is also bad for you!")
} else {
console.log("You slept " + (idealSleepHours - actualSleepHours) + " hour(s) less than you should have this week. Try to get more sleep next week!")
}
};
calculateSleepDebt();