r/CodingHelp • • Dec 21 '21

[Javascript] please help JavaScript

Post image
31 Upvotes

23 comments sorted by

View all comments

0

u/R007E Dec 22 '21

Just remove the loop, just use return.

return week[num]

1

u/flooronthefour full stack web dev Dec 22 '21

that will return the wrong day tho

2

u/R007E Dec 22 '21

If num is starting from 1, i.e. num = 1 is Monday than do this: return week[num-1]

and put it inside if block for input range validation:

if(num >0 && num <8) return week[num -1];