Sleep debt calc

Hi, I’m stuck on that one for few days now. Here’s my code so far:
const getSleepHours = day => {

if(day===‘Monday’){

return 8;

}else if(day===‘Tuesday’){

return 9;

}else if(day===‘Wednesday’){

return 7;

}else if(day===‘Thursday’){

return 7;

}else if(day===‘Friday’){

return 7;

}else if(day===‘Saturday’){

return 10;

}else if(day===‘Sunday’){

return 10;

}

};

console.log(getSleepHours(‘Friday’))

const getActualSleepHours = () => {

getSleepHours(“Monday”)

  • getSleepHours(“Tuesday”)

    • getSleepHours(“Wednesday”)

      • getSleepHours(“Thursday”)

        • getSleepHours(“Friday”)

          • getSleepHours(“Saturday”)

            • getSleepHours(“Sunday”)

};

console.log(getActualSleepHours());

how ever I’m trying to get actual sleep hours, it either doesn’t show anything, or returns as undefined. Any idea what am I doing wrong? Thank you so much!

Hello @ukaszr , welcome to the forums! Do you actually return anything from the getActualSleepHours function?

1 Like

Yeah, I’ve tried both return and console.log, and neither work. I’ve even type the code the very same way as in video in the exercise, and still facing the same problem

Ok, I’ve solved the problem, but I don’t really know how does it happened. I have removed brackets from getActualSleepHours, but I don’t really understand how the function works, doesn’t it supposed to come up as a syntax error?

If you have only one line (which you do, it’s just the formatting that means it doesn’t look like it’s one line), you can use an arrow function without brackets, using something called implicit return:

const someFunc = () => 5;
console.log(someFunc());//will print 5

The function would also have worked had it had brackets, and an explicit return (where you actually write return:

const someFunc = () => {return 5;}

I hope this clears some things up for you!

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