Keep getting idealHours undefined


#1

help! what am I doing wrong here?

function getSleepHours(day){
var hours = prompt('How many hours of sleep did you get on ' + day + '?');
return Number(hours);
}
function getActualSleepHours(){
return getSleepHours('Monday') + getSleepHours ('Tuesday') + getSleepHours ('Wednesday') + getSleepHours ('Thursday') + getSleepHours ('Friday') + getSleepHours ('Saturday') + getSleepHours ('Sunday');
}
function getIdealSleepHours(){
prompt ('How many hours would you like per night?');
return Number(idealHours) * 7;
}
function calculateSleepDebt(){
var actualSleepHours = getActualSleepHours();
var idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours){
console.log('You got an ideal amount of sleep!');
}
else if (idealSleepHours < actualSleepHours){
console.log('You got' + (idealSleepHours - actualSleepHours) + 'hours sleep. girl go get some rest.');
}
else {
console.log('You got' + (actualSleepHours - idealSleepHours) + 'hours of sleep. girl wake up');
}
}
calculateSleepDebt();


#2

return Number(idealHours) * 7;

IdealHours is undefined. There is no variable anywhere named idealHours.
My suggestion is that in the getIdealSleepHours() function, you turn the prompt
into a variable:

var idealHours = prompt ('How many hours would you like per night?');

And now the computer understands what idealHours is :slight_smile:
If you need more help, I'll be glad to help.