I want to do this with JS



This is the code I wrote, hoping that the big guys have a more concise handling method: