Sleep Debt Calc isnt giving output

// var yourID = userinput =>{}

const getSleepHours = day => {

  day = day.toLowerCase();

// switch works like if statement but is shorter

switch(day){

case 'monday':

  return 8;

case 'tuesday':

  return 8;

case 'wednesday':

  return 8; 

case 'thursday':

  return 5;

case 'friday':

  return 3; 

case 'saturday':

  return 11;

case 'sunday':

  return 6;

default:

  return 'Error!';

  }

}

// This is the user input if we asked for it

const getActualSleepHours = () => 

getSleepHours('Monday')+

getSleepHours('Tuesday')+

getSleepHours('Wednesday')+

getSleepHours('Thursday')+

getSleepHours('friday')+

getSleepHours('saturday')+

getSleepHours('sunday');

//Ideal Sleep is 8 hours * 7 days

const getIdealSleepHours = () =>{

  const idealHours = 8;

return idealHours*7

};

// Here we are calling getActualSleepHours and getIdealSleepHours and assigning them ...nfc why.

const calculateSleepDebt = ()=>{

  const actualSleepHours = 

getActualSleepHours();

  const idealSleepHours =

getIdealSleepHours();

if (actualSleepHours === idealSleepHours) {

console.log((idealSleepHours-actualSleepHours)+' Hours, Great Job! you got enough sleep');

}

 else if (actualSleepHours > idealSleepHours) {

  console.log('Maybe time for a social life');

} 

else {

  console.log('Nap time!');

  } 

calculateSleepDebt();

}

Hi so i have been through my code and through the video and when i run this code i get no output. I am assuming from what i can see it is because i am missing console log statements earlier in the code but i am not sure. Could someone nudge me in the right direction please.

Also why are we taught function prefix if everything uses a const/let?

Hi! Welcome to the forums :slight_smile:

Also why are we taught function prefix if everything uses a const/let?

They all have their subtleties and best use-cases. I think they’re just trying to expose you so that if you see other javascript code you don’t go: huh? what’s that?

Could you edit your post and click the format </> button before pasting? It helps everyone trying to help you read it much quicker and find errors efficiently :slight_smile:

1 Like

Hi @katie.packer, welcome to the forums :grinning:

From what I can see, you are calling your calculateSleepDebt() function inside of its own definition, thus it never really runs. You should call calculateSleepDebt() at the end of your code, outside of every other function.

Hope this helps :slightly_smiling_face:

2 Likes

oh how silly of me. Thank you! you saved me from madness!

1 Like

Haha, no problem :relaxed: Glad I could help :slightly_smiling_face:

1 Like