Sleep debt calculator on codecademy

Hello, I’m currently working through the sleep debt calculator project on codecademy! My question is whether or not you need to add an else statement for determining the day. I guess I’m missing the logic behind adding an else statement that checks if it’s a day of the week or not. Seems rather irrelevant as it isn’t possible for it to not be any given day of the week.

I have my else statements for everyday of the week and they all return a value of how many hours were slept on that given day. However, the “get unstuck” video states I require an else statement and will throw an ‘Error’ message to the console if it isn’t a day of the week haha.

Any and all input is greatly appreciated!!

Hello @bit8243770387, welcome to the forums! As far as I can remember, no, the else isn’t strictly necessary for this project; however, it is always good to build your program so that it can handle extra cases. If, for example, this project expanded so you got a user’s input for the day of the week, then you’d definitely need that else block.

1 Like

Hi neutrino! Thank you for the response! However, I am only about a week into coding so everything is very fresh for me. What purpose would the else block serve if the user’s input is always going to be a day of the week?
I don’t mean to come off as naive, but I’d love to have a complete understanding of the concept.

Thank you!

1 Like

If for example you asked the user which day they wanted to get sleep hours for, and they entered “mondy,” you’d want to let them know that they had entered an incorrect date, without just crashing the program.

Wow. Completely overlooked that possibility :man_facepalming: .
Thank you for taking the time to explain!!

1 Like

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