Sleep Debt Calculator: Reference Error actualSleepHours is not defined


Not sure why I am getting the Reference Error: actualSleepHours is not defined. Here's my code:

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() {
var idealHours = prompt('How much sleep would you prefer per night?');
return number(idealHours )* 7;

function calculateSleepDebt() {
var actualSleepHours = getActualSleepHours();
var idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log('You got the perfect amount of sleep!');
else if(actualSleepHours > idealSleepHours) {
console.log('You got' + (actualHoursPerWeek - idealHoursPerWeek) + ' hours more sleep than needed.');
else {
console.log('You need to get ' + (idealSleepHours < actualHoursPerWeek) + ' more hours of sleep!');
if (actualSleepHours < idealSleepHours){
console.log('You got' + (idealSleepHours - actualSleepHours) + 'hours less sleep this week than you need. Get some rest.');
else if(actualSleepHours > idealSleepHours) {
console.log('You got ' +(actualSleepHours - idealSleepHours) + 'hours more sleep than you need this week.');

I am sure the answer is under my nose but I would like some assistance on how to define actualSleepHours in this example.


I found my issue. In the code I included my var

inside the function which was causing it not to define my variables. After fixing that I also had to change

the wording from actualHoursPerWeek to actualSleepHours. That error was from reading the directions as I was too literal lol. But it's great to find your mistake.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.