Something is off


#1

Hello, below is my code

function getSleepHours(day) {
 var hours = prompt('How many hours of sleep did you get on ' + day + '?');
  return parseInt(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 is ideal per night?');
  return parseInt(idealHours * 7);
}

function calculateSleepDebt() {
  var actualSleepHours = getActualSleepHours();
  var idealSleepHours = getIdealSleepHours();
  
  console.log(actualSleepHours + '' + idealSleepHours);

if(actualSleepHours === idealSleepHours) {
  console.log('You have slept well');
} else if(actualSleepHours > idealSleepHours) {
  console.log('You got' + (actualSleepHours - idealSleepHours) + ' hours more sleep than you needed. Do some activity! ');
} else  {
  console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hours less sleep than you needed. Get some rest. ');
 }         
}
  
calculateSleepDebt();

However, when it runs I don't believe the calculations are correct. Like I put in 1 for each hour of sleep for each day & 3 hours for ideal sleep it came back with 721.
Could someone explain what I am doing wrong?
Please & Thanks


#2

It's probably a bit late but there is no problem with your calculations. It returned 721 because of this line : console.log(actualSleepHours + '' + idealSleepHours);>>>> It reads like this :
your actualSleepHours's value is 7 and idealSleepHours is 21(7*3); so it prints 721.

You can change it like this
console.log('Your sleep hours: ' + actualSleepHours + ' and Ideal sleep hours: ' + idealSleepHours);