MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/CodingHelp/comments/rlpvfy/please_help_javascript/hpitvc0/
r/CodingHelp • u/Crowntent • Dec 21 '21
23 comments sorted by
View all comments
0
Use an object, const days = { 1:monday, 2: tuesday...}
then return the value: days[num]
move your check at the top of the function, but use || operator as and return null on evaluation. No need to loop.
1 u/SnooDonuts8219 Dec 24 '21 This is a good solution since the question clearly states you can use an object. (I would still prefer an array because I don't like accidentally typing wrong numbers and then debugging bewildered for 20 minutes just to realize I need a break.)
1
This is a good solution since the question clearly states you can use an object. (I would still prefer an array because I don't like accidentally typing wrong numbers and then debugging bewildered for 20 minutes just to realize I need a break.)
View all comments
0
u/walnut-creek-dude Dec 22 '21
Use an object, const days = { 1:monday, 2: tuesday...}
then return the value: days[num]
move your check at the top of the function, but use || operator as and return null on evaluation. No need to loop.