Sleep Debt Calculator Help

Hey Guys!

I have been having a reference error show up (in relation to the Sleep Debt JavaScript project) after I save my code after completing 5/14 tasks. I’ve been reading the code over again for the past hour. I am also new to coding and JavaScript so still trying to learn how it operates. So, I was wondering if anyone else could help me figure out what the issues are. Thank you in advance!

My code:

const getSleephours = (day) => {

 switch (day) {
   case 'monday':
   return 8
   case 'tuesday':
   return 7
   case 'wednesday':
   return 8;
   case 'thursday':
   return 5
   case 'friday':
   return 8
   case 'saturday':
   return 7
   case 'sunday':
   return 8
   return "Error!"

const getActualSleepHours = () => 
getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') +
getSleepHours('friday') +
getSleepHours('saturday') +


The error:
ReferenceError: SleepHours is not defined
at Object. (/home/ccuser/workspace/sleep-debt-calculator/sleepDebtCalculator.js:36:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

SleepHours does not exist. Look carefully at the names of your functions (particularly the one you are trying to call).


Thank you for pointing that out. However, after making that change, the same reference error is showing up but at a different location.

The new error:


ReferenceError: getSleepHours is not defined
    at Object.<anonymous> **

function and variable names are case sensitive, it looks like you defined it as getSleephours, not getSleepHours.


Whoa! The code has finally worked. I’m going to have to look out for those case-sensitive and variable naming mistakes from now on. Thank you for your help!

1 Like

FYI when you end up coding locally with a good program like VS code they will have auto-complete features for you which saves you time but also helps minimize headaches like this

1 Like

That sounds amazing! I appreciate the information!

This implies that JavaScript is aware of patterns, which it is not. A Regular Expression can be case sensitive, or not. This is how most servers resolve URLs to always (or most times) be able to find a resource as long as all the letters match to the file name.

JavaScript is not case sensitive. It is symbol independent such that ‘A’ and ‘a’ have no meaningful connection or relationship. They are disconnected, distinct and independent. JavaScript is not taking any letter casing into account. The name matches what is in the namespace or it does not. That is all it can do.

1 Like

Here’s an excerpt from the MDN: “JavaScript is case-sensitive and uses the Unicode character set.”

I think I get what you’re saying, that to Javascript “h” and “H” are different characters, but this reply is so semantically dense that I can’t say for sure, and obfuscates the simple point that whether you type “h” or “H” makes a difference. To say that “Javascript is not case sensitive” is misleading at best, even if to it, they are simply distinct characters in a character set.


One can see how this is a controversial argument, and not one to spend much time on being as trivial as it is. Geologists argue whether things are fixed or mobile; analogously this could be the same thing.

Where I stress the communicable difference between how JS sees letters and how regex see them is the boundary between not case sensitive and case sensitive, respectively. This is truly ‘semantic density’ and is rather splitting hairs. If we can see all the layers like a geologist would it is easier to expand on the finer points.

JavaScript is not case sensitive. It does not use pattern recognition. It uses literal identifiers. It does not go to the trouble to test letter case, period. That is implied in a case sensitive implementation.

1 Like


Kindly choose one to work with

Well, I think it’s up to you as the developer, but, getSleepHours would follow the “camel case” convention which is pretty much the standard for naming most variables and functions.

This blog post gives a pretty good overview of conventions in javascript.

Most important thing is being consistent and following whatever convention is being used by your employer, community, open source project, etc…