r/learnjavascript • u/Even-Chicken5282 • Jan 25 '26
I'm having a hard time building up logic in JavaScript functions, do you guys have any tips?
I am a beginner in JavaScript and I can understand normal and higher order functions but applying them seems really challenging, I was wondering if you guys have any tips that I can use to improve, and if there are any sureshot ways to build really strong logic.
Any advice is highly appreciated!
10
Upvotes
3
u/rerikson Jan 25 '26
Build small games, like Pong.
2
u/naqabposhniraj Jan 25 '26
Are you new to programming or have a prior experience?
2
u/the-liquidian Jan 26 '26
It’s a good idea to use unit tests, and look up pure functions.
1
u/iMac_Hunt Jan 25 '26
If you share an example of the type of function you’d like to build up, I can give you a nudge in the right direction
1
u/canyoucometoday Jan 25 '26
replicate something that already exists so you are only solving one problem (learning the language) at one time, chunk everything into pieces, lots of small problems.
also just reps, you need to give it time
1
u/FunksGroove Jan 25 '26
Start small. Solve a small problem with a small function. Then add more. Then refactor as needed. Rinse, repeat.
1
u/_Pixelmancer Jan 25 '26
Allow yourself to forget the overall project and write pseudocode. Basically write yourself a list of things you need to do or calculate in order to get the wanted output, then for each write a list of things you might need to do and calculate and so on until you feel its basic enough. For an example when developing an AI for an enemy in a game you might realize you need to figure out if the player is in the enemy's field of view, and you then come to realize that you need to compare the angle of where the enemy is looking and the angle between the player and enemy. At that point your task should no longer be AI for a mob - it should be "how do i calculate the difference between two angles/vectors"
0
u/lonelyshang12 Jan 25 '26
Ask chatgpt 5 questions each day from beginner level and solve that with understanding at all.
0
u/elg97477 Jan 25 '26
I suggest picking up the Head First Design Patterns book. Study the patterns. They involve how people have built up logic in their code in the past with solutions you can apply today.
-2
u/SeveralSalad9538 Jan 25 '26
Look. Go to the example of Chatgpt. Set him a task so that he explains the tasks to you in the style of "cs50". And throw your examples in there. He will explain everything to you clearly, what you are doing wrong and how you need to, in metaphors. And you already make logic out of it.
0
u/[deleted] Jan 29 '26
[deleted] — view deleted comment
1
u/[deleted] Jan 25 '26
[removed] — view removed comment