What is wrong with my code pls?

https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator

 const getSleepHours = day => {
  switch(day){
    case 'monday':
    return 8
    break;
     case 'tuesday':
    return 7
    break;
     case 'wednesday':
    return 9
    break;
     case 'thursday':
    return 6
    break;
    case 'friday':
    return 10
    break;
    case 'saturday':
    return 6.5
    break;
    case 'sunday':
    return 7
    break;
    default:
    return 'error!'
  }
}
const getActualSleepHours = () =>  {  return getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + 
getSleepHours('Thursday') + getSleepHours('Friday') +
getSleepHours('Saturday') + getSleepHours('Sunday');
}
 

const getIdealSleepHours = () => {
  let idealHours = 9;
  return idealHours * 7;
}
console.log(getSleepHours('wednesday'));
console.log(getIdealSleepHours());
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
 const idealSleepHours = getIdealSleepHours();

  if(actualSleepHours === idealSleepHours){

    console.log("user got the perfect amount of sleep");
  }
  else if (actualSleepHours > idealSleepHours){
      console.log('user got' + (actualSleepHours - idealSleepHours) + 'more sleep than needed');
  }
  else if (actualSleepHours < idealSleepHours) {
        console.log('user got' + (idealSleepHours - actualSleepHours) + 'less sleep than needed. Get some rest');
  }
        else{
          console.log("Error!something went wrong, check code.");
        }
  }


calculateSleepDebt();

Hey @teejaysmart

Please check up on How to Format code in posts or one of the new features Codebytes. Because it is really hard to read your code as plain text without any formatting.

You didn’t say at which step are you stuck? Which makes it harder for us to help :grimacing:

My guess would be that at the last line of your code you’ve just called your function, but you didn’t log it. This was a common mistake by me.

Sorry that I can’t be of more help, and if my answer is too bland. Next time help us help you by formatting the code properly. Thanks for reaching out for help :+1:

Cheers

Thank you for the reply . i have used the codebytes. hope i did it well.
thanks

Welcome to the Get Help category!

const getSleepHours = day => { switch(day){ case ‘monday’: return 8 break; case ‘tuesday’: return 7 break; case ‘wednesday’: return 9 break; case ‘thursday’: return 6 break; case ‘friday’: return 10 break; case ‘saturday’: return 6.5 break; case ‘sunday’: return 7 break; default: return ‘error!’ } } const getActualSleepHours = () => { return getSleepHours(‘Monday’) + getSleepHours(‘Tuesday’) + getSleepHours(‘Wednesday’) + getSleepHours(‘Thursday’) + getSleepHours(‘Friday’) + getSleepHours(‘Saturday’) + getSleepHours(‘Sunday’); } const getIdealSleepHours = () => { let idealHours = 9; return idealHours * 7; } console.log(getSleepHours(‘wednesday’)); console.log(getIdealSleepHours()); const calculateSleepDebt = () => { const actualSleepHours = getActualSleepHours(); const idealSleepHours = getIdealSleepHours(); if(actualSleepHours === idealSleepHours){ console.log("user got the perfect amount of sleep"); } else if (actualSleepHours > idealSleepHours){ console.log(‘user got’ + (actualSleepHours - idealSleepHours) + ‘more sleep than needed’); } else if (actualSleepHours < idealSleepHours) { console.log(‘user got’ + (idealSleepHours - actualSleepHours) + ‘less sleep than needed. Get some rest’); } else{ console.log(“Error!something went wrong, check code.”); } } calculateSleepDebt();

You should try printing the const variables you’re using inside your calculateSleepDebt() function, to see what you’re comparing on lines 43, 47, and 50 in your Codebyte.

I suspect that those values are not what you believe them to be…

1 Like

Thank you it works! i appreciate