Sleep Debt Exercise

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!

1 Like

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.

1 Like

I read this, and I was comparing whith my own exercise, I don’t remember changes that i do ( a lot of “console.log” of course! :slight_smile: ) but then, by the end, I observe, that you declare two new variables, actualSleepHours, and idealSleepHours, but then, in the condictional conditions, you are using getActualSleepHours…

I think that if you read, you can solve… if you didn’t yet…

it works for me…

you not need another console.log, because it’s the return in every conditional condition… you only need to call your function (I think that was the las step of the exercise)…