Sleep Debt Calculator: Error on getActualSleep

I am having issues with the sleep debt calculator project. I keep receiving the error that getActualSleepHours is “not defined”. Please advise!

here’s my code:

Hello @claytonblose01099332, welcome to the forums! Did you want the logic (if…else if…else) blocks to be inside the calculateSleepDebt function?


actualSleepHours is only defined within the calculateSleepDebt function, however you close the function (put the closing curly brace } after the line where you define idealSleepHours. That means the logic cannot access those variables, as they are locally scoped within the function.

2 Likes

Your explanation makes sense but unfortunately I am still having trouble fixing it. I’ve removed the curly braces now and I’m just getting different errors… next steps? (thank you for the help thus far!)

You still need to have curly braces, but only at the beginning and end of the function (like you do with if…else blocks. The syntax for a function is:

const someFunction = (arg1, arg2) => {
   console.log("The function!");
//Any code that you want in the function goes between these curly braces.
}
1 Like