How to learn coding
I've seen many beginners struggling to learn an imperative programming language. CSS and HTML are usually easier to grasp, because of their declarative nature and they are easy to visualize. But JS is entirely different. Why it's so hard to get the basic concepts of a "real" programming language?
Most courses are built around the idea of showing how it's done. They structure their content in a way that introduces a new concept then show some examples with descriptions why they work.
When newcomers make their first step in programming, they usually do it just as they learn a natural language. How do you learn a foreign language? You see patterns. Certain constructs or key words that make up the core of what you want to say. And when you talk to someone, you say those key words and hope that the other party understands.
Back then, I wanted to know the price of something in a bakery in France. I just pointed to it, and asked: Euro? I immediately got the answer.
But unfortunately, programming languages are different. You can not just use the key words and hope that the computer understands you. People have intelligence, but computers don't.
The source of this confusion is that software is so complex, it's like a living organism. How often do you say something like "please work" to your laptop? But again, you can not code like this.
The problem with the approach almost all courses take is they only show working programs. Learners start to recognize the patterns, so they have a feeling what the program does. Just like in a natural language, they recognize the patterns and know the meaning of a sentence.
But when faced with a coding challenge, learners struggle. They write a piece of code that has all the required patterns, but if it does not work, they are stuck, unable to figure out what is wrong.
A familiar example to this is number comparison. A course shows that you can compare a variable with a number with i > 0 and i < 10. When a task is to do both, the learner writes 0 < i < 10. It contains all the familiar and seemingly required patterns. How would they know what is wrong?
The thing is, you need to learn how programs really work. Not just the patterns that are only helpful to figure out what a working program does, but the underlying rules. Don't treat a programming language like a natural one.
When you start seeing expressions, you'll immediately know what the problem with the above code is. It is interpreted as (0 < i) < 10, and the left operation returns a boolean, and comparing a boolean with a number is obviously not what you wanted.
You need to learn the basics. After that, you can use the patterns to recognize common structures. But unless you have a method to see code as it really is, you'll be stuck. Learn how to read code.