"Sleep Debt Calculator" project

I’m having trouble with the project “Sleep Debt Calculator”. This is what I have for it so far but it keeps having an error in the code. I don’t know what I am doing.

const getSleepHours => {

if(day === ‘monday’) {

return 8;

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

return 7;

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

return 6;

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

return 5;

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

return 4;

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

return 3;

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

return 2;


return 'Error!';


else {


switch (day) {

case 'monday':

return 8


case 'tuesday':

return 7


case 'wednesday':

return 6


case 'thursday'

return 5


case 'friday'

return 4


case 'saturday'

return 3


case 'sunday'



Hey @blog0369955490

Which step are you stuck at? :grinning_face_with_smiling_eyes: Remember to log your code, to test if everything works properly/as you want it to. Especially in these small projects we get, because we can’t get an error if it’s incorrect, just a syntax error.

I don’t think you need an empty else statement (you can just delete that one, since it does nothing anyway). And it seems that you have both if/else if & switch statements together in 1 function. But both of them are doing the same thing :man_shrugging:

I know that this wasn’t of much help, but try to figure it out yourself. If you’re stuck at a certain step, just go practice the previous lessons and try to connect the dots. Or study from different sources on the same topic. It takes time on the side, but for me it was really helpful.

Let us know if you’re stuck again!


note: JavaScript, not Java

It looks like you’re trying to do a switch block and a bunch of if-else stuff at the same time
but you only need one of those things here (use either the switch statement only, or the if-else stuff only)
Note that the default does not belong inside of an else-if
default: should only be in the switch block

Also, the getSleepHours function is missing the parameter (day)

// JavaScript const getSleepHours = day => { if (day === 'monday') { return 8; } else if (day === 'tuesday') { return 7; } else if (day === 'wednesday') { return 6; } else if (day === 'thursday') { return 5; } else if (day === 'friday') { return 4; } else if (day === 'saturday') { return 3; } else if (day === 'sunday') { return 2; } else { return 'Error!'; } } let when = 'monday'; console.log(when); console.log(getSleepHours(when));


For practice, you could try to do it using a switch statement instead of a bunch of if-else stuff too.

1 Like

For context, this topic was originally in Get Help >> Java.

1 Like

I have since figured out what was wrong by doing it over again. Thank you all!