# Sleep Debt calculator help

#1

Hello i am currently stuck on this task

I cannot understand where I am going wrong and any help greatly appreciated. Thanks.

const getSleepHours = day => {
switch (day) {
case 'monday':
return 8;
case 'tuesday':
return 7;
case 'wednesday':
return 6;
case 'thursday':
return 8;
case 'friday':
return 5;
case 'saturday':
return 6;
case 'sunday':
return 10;
}
};
const getActualSleepHours = () => { getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday')
return getSleepHours;
}

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

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log('You got a perfect amount of sleep');
}
if (actualSleepHours < idealSleepHours)
{
console.log('You got ' (idealSleepHours - actualSleepHours) +  ' Get some rest, maybe take a nap');
}
if (actualSleepHours > idealSleepHours)
{
console.log('You got ' + (actualSleepHours - idealSleepHours) + 'thats more than enough sleep');
}
const idealSleepHours = getIdealSleepHours();
};

calculateSleepDebt();

#2

here:

if (actualSleepHours === idealSleepHours)

ReferenceError: idealSleepHours is not defined

which is pretty self explaining? idealSleepHours is undefined, as such it canâ€™t be used in a comparison. undefined variable could also mean out of scope, that is possible as well

#3

â€śwrongâ€ť is a difference between what you expected and what you saw

for future reference, you should explain what those are
a question should convince the reader that you canâ€™t solve it and help the reader understand what youâ€™re missing

#4

Thanks for responding, I am unsure as to move on still.
How do I define idealSleepHours? or could you give an example of how you define something so that I can have go

#5

you have a function capable of calculating the ideal number of hours sleep required? So, you can use this function to define a variable idealSleepHours in a very similair fashion as actualSleepHours

#6

Ok, thanks I will make sure to explain exactly why is is not responding in the way i expected.
I am very new to this and find it hard to even articulate how I expect things to workâ€¦

#7

Thanks again, I think I have solved that but I am getting nothing when I run the code?!?!

Here is my code:

const getSleepHours = day => {
switch (day) {
case 'monday':
return 8;
case 'tuesday':
return 7;
case 'wednesday':
return 6;
case 'thursday':
return 8;
case 'friday':
return 5;
case 'saturday':
return 6;
case 'sunday':
return 10;
}
};
const getActualSleepHours = () => { getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday')
return getSleepHours;
}

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

};

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log('You got a perfect amount of sleep');
}
if (actualSleepHours < idealSleepHours)
{
console.log('You got ' (idealSleepHours - actualSleepHours) +  ' Get some rest, maybe take a nap');
}
if (actualSleepHours > idealSleepHours)
{
console.log('You got ' + (actualSleepHours - idealSleepHours) + 'thats more than enough sleep');
}

};

calculateSleepDebt();

I am finding this really tough goingâ€¦ I really appreciate the help and will take a couple of hours away then come back to it.

#8