Writing code is about breaking things down into tiny steps. Maybe you need to write an algorithm and then define each tiny step on paper first. Don’t try to start writing code until you have the whole thing figured out in plain English first. Then work on each solving each step with code, one at a time. I hope this helps.
Keep trying, if the book or article your reading about java script, doesn’t help, keep trying to find the video, or book that will help.
A Lot of info out there, but not all of it, helps you deeply understand, and retain what you learn. Try small, fun projects, to boost your confidence.