# Sleep Debt calculator - I have no idea what's wrong

hi. Im sitting for 2 hours trying to solve errors in my code. Any ideas why its throwing me errors?

``````const getSleepHours = day => {
switch (day){
case 'Monday':
return 8

case 'Tuesday':
return 7

case 'Wednesday':
return 6

case 'Thursday':
return 7

case 'Friday':
return 5

case 'Saturday':
return 10

case 'Sunday':
return 10

default: console.log ('WTF mate')
}
}

function getActualSleepHours(){
return getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + getSleepHours('Thursday') + getSleepHours('Friday') + getSleepHours('Saturday') + getSleepHours('Sunday')

}
const getIdealSleepHours = () => {
const idealHours = 8
return idealHours * 7
}

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

if (actualSleepHours === idealSleepHours) {
console.log('You got the perfect amount of sleep')
} else if (actualSleepHours < idealSleepHours) {
console.log('Get some sleep m8. You need' (idealSleepHours - actualSleepHours) + 'hours more of sleep')
} else if (actualSleepHours > idealSleepHours) {
console.log('You are lazy. You slept' (actualSleepHours - idealSleepHours)+ 'over what you need') }

calculateSleepDebt()
``````

Welcome to the forums!

In this snippet of code:

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

if (actualSleepHours === idealSleepHours) {
console.log('You got the perfect amount of sleep')
} else if (actualSleepHours < idealSleepHours) {
console.log('Get some sleep m8. You need' (idealSleepHours - actualSleepHours) + 'hours more of sleep')
} else if (actualSleepHours > idealSleepHours) {
console.log('You are lazy. You slept' (actualSleepHours - idealSleepHours)+ 'over what you need') }
``````

You are trying to reference `actualSleepHours` outside of the function where it is defined, so itâs out of scope. By the looks of it you would want the conditionals to be inside the function.

1 Like

if i put it in the funcion errors dissapear but if i try to call the function i get:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:43
console.log(âGet some sleep m8. You needâ (idealSleepHours - actualSleepHours) + âhours more of sleepâ)
^

TypeError: âGet some sleep m8. You needâ is not a function
at calculateSleepDebt (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:43:45)
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:48:1)
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)

1 Like
``````console.log('Get some sleep m8. You need' (idealSleepHours - actualSleepHours) + 'hours more of sleep')
``````

Check how you are combining the three strings together, youâre missing the `+` between the string and the variable.

thats it! Thank You very much! Both asnwers needed to be implemented.

1 Like

No problem, glad I could help!

Happy coding!

1 Like