Problem in JavaScript's functions project (Sleep debt calculator) please help-

Hello!
I am very new to programming and have started with JavaScript, while working on a function’s project called ‘Sleep debt calculator’, whenever I call the function getActualSleepHours, I get NaN on the console, and I am unable to figure out why. Below is the code I wrote, please help me figure out the issue-

function getSleepHours(day){day=day.toLowerCase()

if(day===‘monday’){return 8;}

else if(day===‘tuesday’){return 9;}

else if(day===‘wednesday’){return 8;}

else if(day===‘thursday’){return 7;}

else if(day===‘friday’){return 8;}

else if(day===‘saturday’){return 9;}

else if(day===‘sunday’){return 10;}}

console.log(getSleepHours(‘sunday’));

function getActualSleepHours(){return getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesdsay’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);}

console.log(getActualSleepHours());

Thanks!

Hi!

Welcome to the forums :slight_smile: in the future, pressing </> before pasting will format your code and make it easier to troubleshoot.

That being said, I think your issue is this typo getSleepHours(‘wednesdsay’).

Thankyou so much, its incredibly embarrassing to find this fault even though i checked the code for typos several times. :slight_smile:

1 Like

Not at all!!

It happens to me plenty. I’m usually happier when its a typo rather than some serious bug.

1 Like