Nice solution in the JavaScript, i didnt knew You could do all that in just one function, i always thought that everything should be in diferente functions, i did ir that way and find myself in trouble with they calls of the funtions, pretty straight forward, and understandable, congrats!
1