At the end of the day, I’m just trying to guide you down the easiest path. You’ve reiterated several times that you know nothing about JavaScript/code or how to incorporate your changes into the final project, so following those cues, I’m suggesting that you stick with the first code example because you’ve shown evidence of editing and manipulating it successfully, and it isn’t too far off what you describe.
Changing up the codebase now is just going to put a lot more research, learning and effort your way.
…
There is another way to read those earlier cues though… are you actually asking for somebody to (re)write the code for you? Somebody may step in with plug-and-play code that meets your requirements, but it’s unlikely. Ultimately, if this is the case, you might want to consider hiring somebody.