Sleep Debt Exercise


#1

Hello! Wondering if someone could help me with this:

const getSleepHours = day => {
switch (day) {
case ‘monday’:
return 8;
break;
case ‘tuesday’:
return 8;
break;
case ‘wednesday’:
return 10;
break;
case ‘thursday’:
return 8;
break;
case ‘friday’:
return 6;
break;
case ‘saturday’:
return 7;
break;
case ‘sunday’:
return 12;
break;
default:
console.log(‘Error!’);
break;
}
};

const getActualSleepHours = () => {
return getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesday’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);
};

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

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log(‘Perfect amount of sleep!’);
} else if (getActualSleepHours > idealSleepHours) {
console.log(‘You got ’ + (actualSleepHours - idealSleepHours) + ’ hour(s) more sleep than you needed this week. More sleep than needed!’);
} else if (getActualSleepHours < idealSleepHours){
console.log(‘You got ’ + (idealSleepHours - actualSleepHours) + ’ hour(s) less sleep than you needed this week. Get some rest.’);
}
};

console.log(calculateSleepDebt());

It says “undefined” when I run it…

Thank you!


#2

By calling console.log here:

console.log(calculateSleepDebt());

you log the returned value, calculateSleepDebt doesn’t have a return value, so JS gives undefined to indicate the absence of a return value.