3 line isn’t that much, so I’d focus on why after three lines you start getting confused and you isolate that issue. It could be anything like confusing naming conventions, complex problems (math problems are dense), over complexity, and or not understanding the original issue at hand.
It sounds like you kinda get the syntax of the language, but I’m not sure if you actually understand what the syntax means. There is a difference between knowing words, and having an expansive vocab, and understanding what a poet means in his poems. Yes you can understand the words, but understanding the meaning of those words is totally different.
When your just starting out you need to focus on the basics, mainly the flow of logic from 1 line to the next and how different syntax affects the code.
I want to point out programming its not easy to do. Jumping to other languages wont change the fact programming is hard and complex. (Python actually has easier to learn syntax compared to JS, and less funky quirks) It maybe difficult, but I believe anyone can do it, as long as they have three things. If you have time, grit and an internet connection you can learn programming. Time gives you time to study, time to bash your head against the wall, and gain experience thru failure. Grit keeps you at it even though you just spent a bunch of time bashing your head against the wall!. An internet connection will give you a way to tap into basically infinite knowledge, it just make time and some good google-fu to get those answers.
You will feel stupid on day 1 and day 10000. If you don’t, then you aren’t learning anything worth learning. You get experience by being stuck, and figuring it out after a while. Stick with it and keep grinding against the problems you have. If you don’t understand something, google it, figure out what you can, test it out yourself, rinse and repeat.