Nothing happen to the calculator


#1

#2

Hi @ajaxcoder76301,

May I ask is this one of the projects for Pro membership?
I asked because I do not have the link nor access to the project itself.

I only can give you suggestions based on your code.


Syntax:

At the very end of calculateSleepDebt() function, you missed a closing } bracket for an IF statement:

  if(actualSleepHours > idealSleepHours){
    console.log("too much");    //<====== Note: close this missing part with }
  if(actualSleepHours < idealSleepHours){
    console.log("get some sleep")  
  }      //<====== This closes the above IF
  };    //<====== This closes the function
}       //<====== And delete this extra curly bracket }

Next

To make your code works, you need to change one spelling mistake:

else if(day === “saturaday”){return 10;}

Change that “saturaday” to “saturday” under the getSleepHours() function, then your code will output the desired result.

Explanation:

What happens is that when you misspelled “saturaday”, your getSleepHours() function returned 35invaild9 which is not what you wanted, you would want it return a number value.

So this 35invaild9 continue to be a problem in calculateSleepDebt() function where the code would perform comparison and etc, thus leading to undefined being returned out of the function.


Extra commentary:

Based on your code:

  • It is better to use switch cases rather than the if/else if/else statements for getSleepHours() function (you have like 8 cases there).

  • Nevertheless, if/else if/else works the same if you insist.

  • For calculateSleepDebt(), why not using If/else if/else if statements, but using if/if/if would still work the same.

  • In your code, make sure the consistency of using either double quotation marks " " or single quotation marks ’ ', using both is rather confusing and not the best practice, choose and stick to one type.


That’s all, have fun coding. Cheers! :slight_smile: