Found a different way to do Javascript Sleep project, am I correct? (Pro Career JavaScript Project)

Hi everyone,

This is my first post and I’m new to coding so not sure if I’m understanding this project correctly. I got this task in the Javascript Project on Sleep Debt. It says to create two new variables in the function block. Then it wanted me to refer to these variables later on which created an error undefined variable message for both.

I looked into this on google, and found ‘Wrong Scope’ which said that I should move the variable outside the function block so that the computer could use it throughout, not just inside the function block.

I tried this and redefined my function without these variables inside the function block. I added another function calculateSleepSurplus just to make my life a bit easier doing calculations for too little vs too much sleep (not sure if creating a new function was a good decision though). This got me the console log output that I wanted. There is a screenshot of my new way below

Essentially, I was wondering if the task was written incorrectly or if I have massively diverted from the path it wanted me to do? Also on the new path I took did I make any mistakes?

Thanks!