Sleep Debt Calculator


#1

I'm working on this project at the end of JS Functions. The code seems right but I'm getting an error message. Any suggestions welcome!


https://www.codecademy.com/en/courses/learn-javascript/projects/sleep-debt-calculator?link_content_target=interstitial_project


ReferenceError: actualSleepHours is not defined


function getSleepHours(day) {
  var hours = prompt('How many hours did you sleep ' + 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(day) {
  var actualSleepHours = getActualSleepHours();
  var idealSleepHours = getIdealSleepHours();
}
if(actualSleepHours === idealSleepHours){
  console.log('You\'re on track! You got ' + actualSleepHours + 'just like you wanted!');
}
else if (actualSleepHours > idealSleepHours){
  console.log('You should be feeling nice and rested! You got ' (actualSleepHours - idealSleepHours));
}
else if(actualSleepHours < idealSleepHours){
  console.log('You\'d better turn in early tonight! You got ' + (idealSleepHours - actualSleepHours));
}

getSleepDebt();


#2

It seems like you intend to have the code below inside the calculateSleepDebt function, but it's actually outside of it.

if(actualSleepHours === idealSleepHours){
  console.log('You\'re on track! You got ' + actualSleepHours + 'just like you wanted!');
}
else if (actualSleepHours > idealSleepHours){
  console.log('You should be feeling nice and rested! You got ' (actualSleepHours - idealSleepHours));
}
else if(actualSleepHours < idealSleepHours){
  console.log('You\'d better turn in early tonight! You got ' + (idealSleepHours - actualSleepHours));
}

Also, getSleepDebt() is being called, but there doesn't seem to be a function with that name defined anywhere.


#3

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