Stuck on JavaScript Algorithm Challenges

Hey guys,

I’m having quite a hard time figuring out how to even begin solving the javascript challenges. When I worked through the basic javascript exercises, everything made sense. However, when I’m on my own to write the code for the algorithm problems, I just draw blanks. Any advice as to how to overcome this? Any good resources?

Thanks in advance!


Hi Colin,
Its normal I feel to sometimes find it difficult to solve the javascript challenges. I could try and tell you something that works for me.

1 Try to simply read the algorithm problem.
2 Then take a pen and paper and try to simply think of the solution without thinking about code.
3 Once you have a plan as to how to tackle the problem, then start coding away at it.
4 This way you can look up resources on specific syntax etc. But ur original solution is already kinda built on paper.
5 You can obvioulsy also google and search for stack overflow, but i think its good to struggle a bit with steps 1 to 4 and then when you feel you have tried enough you can google to figure out how to solve the problem.
6 I feel this kind of helps me.

Hope this helps you


Thanks! I’ll definitely give that a shot!

I was going to do a long reply but Sushmeet said it well enough.

I would just add that you can ask here as well. Just ask very specific questions and provide samples of what you’ve come up with so far.

I would recommend working on the code in a separate environment (codepen, etc.) while you’re developing the answer so you can have some more control and be able to test output. I would also suggest coding in steps - test each step and see how it works.

1 Like

Awesome. Thanks for the advice!

Hi @jazztbone2b,

I do much like @Sushmeet said, exempt I don’t use paper. The solution is often in the question, so I always read the problem statement carefully. I then think to myself what steps I need to take to answer each aspect of the problem.
If I get stuck, or have a hard time just getting started, I code up the parts I think are clear to me, then I go back and ‘join’ them together.

Sometimes the best way to start is to just start coding. The answer usually presents itself.

Hope this helps


[quote=“RockLobster7, post:6, topic:133453”]… exempt I don’t use paper. The solution is often in the question, …
Sometimes the best way to start is to just start coding. The answer usually presents itself.[/quote]

For many simple problems this will be the case. And some people are better at organizing their thoughts on the fly and visualizing things without having to write them down. I consider myself one of them. But then there was a point, where things got too complicated and I had to write them down or at least sketch them out a little.

Different people are going to have different needs. But most people will reach a point of complexity where it is impossible to visualize the whole thing and a little planning will improve the quality of the code and speed things up. And developing those skills early can be a good thing - so they’re there when you need them. Sometimes I even retroactively sketch out of program that I’ve already done, just to understand the process.

Like the old programmer saying goes, “Weeks of coding can save you hours of planning.”

Yeah I learn much better when I write things out on paper. It helps everything just stick better for me! I’ve only been coding for about 2 months now, off and on, and I’ve only been working with javascript for about two weeks. I’m sure it will start to sink in. I really do appreciate the advice!

I don’t think anyone else mentioned it, but Test Driven Development (TDD) can help. Writing out a set of tests often suggests a solution. The TDD approach is also a great habit to develop as a programmer. There’s a series of courses on EdX that you might look into, Systematic Program Design (SPD), that teaches good techniques for TDD and problem solving more generally.

Something else that comes to mind is related to the saying that when all you have is a hammer, everything looks like a nail. When I first started out with Python, I was most comfortable with loops and variable assignments. They were intuitive, and I tended toward solutions using what I knew well. I see this a lot with other beginners too. However, it’s hard to do great work with a Iimited toolkit. I am much better at solving problems now that I’m more comfortable with recursion, map, filter, reduce, and so on (all things that the SPD courses teach really well, BTW). I’ve used these tools heavily as I’ve been working through the intermediate challenges here.

Hi @ksjazzguitar, i totally agree with you. We all have our own way of working through a problem. In the end do whatever works for you and helps you get the required result. Sometimes i find going for a long walk helps me. I would maintain however, that the best way to get going - specially when really stuck - is oftentimes to just start coding. Be weary of ‘analysis paralyses

all the best

1 Like

kinda building off of what has already been said, one way to help organize your thoughts would be to try the pseudo code method:

try not to get overwhelmed by all the unknowns; instead, focus on what you do know. list down unknown / known variables to keep everything organized. it might also help to break down your main goal into smaller, more manageable mini-goals.

also look at the expected output to try to identify a pattern of what the algorithm is expected to do.

and, like what others have said, take a break if you’re getting frustrated.

1 Like

Wow, thanks for all the ideas guys! I’m going to take all the advice into consideration and see what works best for me.

Hi Colin,
Firstly, don’t forget to breathe before you begin any of the javascript challenges. Next, read through the challenge a few times, so that you understand what is needed from each challenge. Then, once you’ve done this, sit in front of your computer, open up Excel, and write down each step in a logical manner, how you think the problem will be solved. If you think you need to use a SORT algorithm or a FOR…LOOP then go back to those sections in freeCodeCamp and understand how each of those things work.

Then start to apply those things to your individual steps that you’ve mapped out in Excel. Sometimes, the challenges are much, much EASIER than we originally thought they would be after we’ve analyzed the problem. You can only get through each challenge in a methodical manner, that’s how coding works. Good luck & all the best!

Thanks for the advice man! Things are slowly started to click. I’ve been writing down ideas and trying to sort through them and that seems to help me make connections. And yes, some of the challenges have such simple solutions! I tend to overthink and try too much. I’ll get there. Onward and upward!

Just a little update…

After working through a JavaScript course over at, I’ve become more comfortable with JavaScript.

I’m back at it with the algorithms and things are starting to click! I’ve been writing the problems down, taking breaks between problems, reading over the problems and thinking of them while at the gym, and I’ve got to say, my whole thinking is changing!

I’ve worked through about half of them and I’ve been able to come up with solutions rather quickly. It feels great taking the problem apart, using to run my code and piece the problem together. This is really fun. Can’t believe I’m getting the hang of this!

Thanks guys for all your advice and words of encouragement!

The algorithm challenges require you to change your thinking styles and for the first time you have to think like a programmer. It will take time to get used to the new thinking style and it’ll take time to solve them, but remember that you can do it :slight_smile:

1 Like

Can you provide the link to the edX courses you mention. I would greatly appreciate it

Google resulted with this:

bummer, the class has been archive and only people who enrolled can view its contents