calculateSleepDebt undefined output


#1

Hi im on the Sleep Debt Calculator project within JS.

My code runs and returns as expected, except the lat line of output says undefined.

Heres the output:

8
56
56
You are sleeping the perfect amount
undefined

Heres my code:

const getSleepHours = day => {
if (day === ‘monday’) {
return 8;
} else if ( day === ‘tuesday’) {
return 8;
} else if (day === ‘wednesday’) {
return 8;
} else if (day === ‘thursday’) {
return 8;
} else if (day === ‘friday’) {
return 8;
} else if (day === ‘saturday’) {
return 8;
} else if (day === ‘sunday’) {
return 8;
}
}

const getActualSleepHours = () =>
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 are sleeping the perfect amount’);
}

else if (actualSleepHours > idealSleepHours)
{
console.log(‘You have too many hours too much sleep per week’);
}

else if (actualSleepHours < idealSleepHours){
console.log(‘You need more hours more sleep’);
}
}

console.log(getSleepHours(‘monday’));
console.log(getActualSleepHours());
console.log(getIdealSleepHours());
console.log(calculateSleepDebt());


#2

Your functions are logging, so don’t log the function calls.

console.log() has no return, hence, undefined.


#3

Ahhh, thanks mtf thats worked

doh!
:grin: