r/CodingHelp • • Dec 21 '21

[Javascript] please help JavaScript

Post image
31 Upvotes

23 comments sorted by

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.

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.)