Sleep Debt Calculator Project Issue

Hello guys. I have been playing with this project Sleep Debt Calculator and have come up with a code like this shown below.

function getActualSleepHours(){
 return Math.floor((Math.random()*8) +4) * 7
}

function getIdealSleepHours(){
  var idealHours = 6.5 * 7
  return idealHours
}

function calculateSleepDebt(){
  var atualSleepHours = getActualSleepHours()
  var idealSleepHours = getIdealSleepHours()

  if (atualSleepHours === idealSleepHours){
    return 'Perfect amount of sleep'
  } else if (atualSleepHours > idealSleepHours){
    return 'Got more sleep than needed'
  } else if (atualSleepHours < idealSleepHours){
    return 'Need some rest'
  }}
console.log(`My ideal sleep hours are ${getIdealSleepHours()} per week.`)
console.log(`I got ${getActualSleepHours()} hours of sleep this week.`)
console.log(calculateSleepDebt()+'.')

Please check the attached image. In first case it was 70 hours which is more than 45.5 but it logs ‘Need some rest’ which is wrong. In second case it was 56 hours which is also more than 45.5 and it logs ‘Got more sleep than needed’.
Is this the editor bug or am I doing something wrong?! Sorry there is image only for 70 hours example because I was not able to add 2 images per post.

1 Like

Actually, here is the second image :blush:

In first case it was 70 hours which is more than 45.5 but it logs ‘Need some rest’ which is wrong.

Think about what your logging to the console vs. what you are computing. Consider what happens when you call your function getActualSleepHours() more than once.

Check your consistency of spelling with actual vs atual. But it shouldn’t make a difference here.

Welcome to the forums :slight_smile:

2 Likes