Understanding vs Writing It Out

It has been a frustrating journey for the last few months. I am not sure what will come out of this but I thought I should at least share my thoughts with you all. Thank you for taking the time to read this nonsense. I am currently learning JavaScript and stuck at the “Basic Algorithm Scripting” section. I think I understand the concept and different methods but I always come to a blank when I am trying to write the code. I know what they are asking me to do and have some sense in how I should approach it but I feel lost and defeated when I start typing. It’s like all the knowledge that I’ve gained over the past few months are in my head but I can’t seem to put it together. Any thoughts or tips? :pensive:

Algorithms are just one part of coding. It is an important part, but it is only one part. Really algorithms are largely language independent - a bunch of programmers who work in different languages can discuss the algorithm. So you first have to understand the algorithm, then you have to understand how to implement it in your language of choice.

How do you get good at them? You just have to do them. Just give it your best shot. If you get stuck, see what others have done. That is still learning. Then come back a month later and see if you can manage it on your own. Just keep doing it and gradually these ideas will make more sense and your ability to implement them will improve. Don’t get frustrated - a lot of people struggle with this.

1 Like

I would suggest that you build a couple projects on your own for something that excites you. Or refactor an old project with that excites you.

Also, you should try creating a project where you it is just a bit ahead of your knowledge. Then Google what you don’t know, learn as you go!

1 Like

Don’t start typing until you have a plan. Get a paper and pencil and work through the logic of the problem. I’m not telling you to handwrite the code, but to write down all of the steps of you solution. You can (and should) even test it out before writing the code by taking an example input and walking through all of your steps to see what the values are along the way. Trying to start with code will often just result in having a lot of bad code on the screen.

2 Likes

When starting out there are usually 2 “sides” to having problems when it comes to solving a programming problem.

The first “side” is understanding the algorithm and solution to the problem.

The second “side” is understanding how to implement the solution to the problem via code.

Identifying which “side” of the problem will help you get the help and knowledge you need to solve the tough problems you run into :smiley:


For example, lets take the Find the Longest Word in a string problem challenge as an example, for how you can take a problem you might not understand, identify what you know/don’t know and find the solutions to said problem.

A good approach for starting out is “how would I as a person solve this in real life”. For the above challenge I think its far to say you’d read the string given, find the largest word, and say that is the longest. Its possible for more complex challenges you might not know how to solve the problem in real life, this can be said to be domain knowledge. Finding help/answers for domain knowledge doesn’t require knowledge of programming, just knowledge of the domain problem.

So now comes the “fun” part where you need to take the algorithm and implement it into your code. Splitting up the algorithm you end up with steps that look more or less like this pseudo-code (this is code that is made up with our own readable syntax):

longest_word = first word in string
for every word in the string:
  if the word is greater than longest_word:
    longest_word = word

return longest_word

Again, the above code is made up using our own code that is more readable.
Taking this pseudo-code, you want to implement it into JavaScript. Essentially you can take each line by line and translate it to what you know in JS. If you don’t know how to do such for a given line, thats when you google for help with the language syntax.

Let’s say you don’t know how to translate: “for every word in the string:” to JS, you’d google “looping in JS” and end up on a page like this.

Most of the challenges build upon previous knowledge the curriculum already went over, so if you feel lost with any syntax you find, but feel like you should of learned it, go back a few challenges, or search to refresh your memory on the subject. Don’t expect to go thru a challenge and remember it without using it a few times. Even then you might have to lookup some stuff, just try to remember what tools you have available, and you can always lookup how to use them down the line.

Finally, you should have some code that may or may-not work. At this point your code might have bugs that prevent it from passing the tets. This is where you should review your own code to determine how it works through experimentation, this process is called debugging. Usually I recommend understanding how the current code works before trying to guess your way to solving the problem, as you lose out on any insight you’d gain by debugging the problem and understanding your own code.

You should keep grinding, and possibly going back through previous parts of the curriculum to refresh your mind. Programming is hard, and takes time and grit, but I believe anyone can do it!

Goodluck!

I really appreciate all the tips and encouragement I got from you all! Thank you for taking the time to share your wisdom. It really means a lot to me. I will definitely keep moving forward!