I am really bad at thinking a solution, e.g. I took 3 hours to build this but now if I wanna put a new feature onto it e.g. close everything else when any button is clicked and open only content div for that one. This is one example, I lack problem solving skills and logical thinking and then implementation. How can I build confidence? e.g. every problem solving / code a solution interview I do, I fail. I need from community
There isn’t a silver bullet it takes work, persistence, and patience. It is like everything else in life the more you do it the better you get.
You also have to make a distinction between using the knowledge you have and learning the new things you need. You can’t come up with solutions to problems by thinking about them if they require prerequisite knowledge you do not yet have. Logical thinking does not remove the need for reading docs and learning the APIs you are using.
As an aside, you are not using the correct array method. If the method does not need to return anything it is just a forEach, not a map.
For the problem you are trying to solve event delegation is one option. You add the listener to the document (or some parent) and look at the click targets to do the logic.
@miketandy is onto something with writing down task requirements.
focus on the solution
write down the requirements
what code or skills are required?
break down the larger problems into smaller manageable ones
Most importantly - what worked for you in the past? (no need to share, just think about how you solve problems, your problem solving style) .
Build a repertoire of design / problem solving skills.
If you can, watch some Ted Talks or other videos about design and related topics to gain inspiration.
The key here is to take a consistent approach and build on the skills you already have.
If you need help solving logical problems, consider studying logic.
A few introductory videos, articles, or blogs should be enough to gain a general understanding.
@ArielLeslie mentioned, problem solving is often about being able to recognise similarities.
Buy basic maths ( aptitude, logical problems etc ), sudoku book and start spending daily 15 minutes
Basically just like our body muscles, brain has got brain muscles ( neurons ) and you need to make sure you keep building new connections. ( learn more on YT )
The more creative work we give to brain, it helps in building new neural network and improve problem solving or other skill ability gradually.