Creating a function just to change names?

I just completed the Sleep Debt Calculator project in the JavaScript Functions module, and I wonder about the function below (from step 8; I’ve left out the if/else if/else portion).

What is the purpose of creating a variable “actualSleepHours” that is equal to the already defined variable “getActualSleepHours”, and same with reformulating “getIdealSleepHours” into “actualSleepHours”? Why not write the calculateSleepDebt function using the two variables that start with get? It seems an unnecessary and cumbersome step.

Apologies if I’m using incorrect terminology. I’m a beginner.

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

actualSleepHours would be a number.
getActualSleepHours is a function.
getActualSleepHours() is a the result of calling that function, which is the number the function returns.

So actualSleepHours and getActualSleepHours are not the same thing.
And yes, it is possible to do everything without having an actualSleepHours variable, but it would probably be easier to have such a variable if you do multiple things with that number.

1 Like