freeCodeCamp Algorithm Scripting

Dylan Attal
5 min readFeb 6, 2019

--

Hi everyone!

This series of articles is geared toward coding beginners completing freeCodeCamp, but anyone who is interested in learning more about solving algorithm scripting challenges can benefit! The goal of this series is to provide solutions and detailed explanations to the algorithm scripting challenges that are part of the JavaScript Algorithms and Data Structures Certification section of freeCodeCamp.

Skip to the end of this article for a list of algorithms I have made posts for.

When I first began learning to code, I signed up for Codecademy and freeCodeCamp. I think that both are excellent resources, and they helped me make the first steps into programming. I think that my experience with freeCodeCamp as a beginner dev was pretty familiar: I breezed through HTML and CSS, I loved learning basic JavaScript, and I hit a brick wall when I arrived at the JavaScript algorithm scripting challenges.

As a beginner, I was confused and overwhelmed. Why did I need to solve these algorithm challenges? What is a for loop? Why would I ever use a for loop? What are all these arcane functions and methods? I don’t come from a math background! I don’t know how to factorialize a number period much less through the magic of JavaScript! Panic ensued. I felt like I was good at HTML and CSS, but maybe I just can’t get writing algorithms. Maybe I’d never be a developer! Maybe I was foolish to ever think I could change careers!

Actual footage of me six algorithm scripting challenges into freeCodeCamp.

Suffice it to say that solving algorithms was not my cup of tea. I decided to plow through them and focus on what I was understanding from freeCodeCamp at the time. I basically just clicked on the Get A Hint button for every challenge and copied the solutions there without fully understanding them. Hopefully this series of articles can provide you with a better resource to understand:

  1. What an algorithm is
  2. What the best way to solve and algorithm challenge is
  3. Different solutions and explanations for each algorithm challenge

Let’s tackle the first two objectives right now! Firstly, what is an algorithm? A quick Google search reveals that

An algorithm is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Algorithms aren’t specific to coding, but they’re especially useful because they allow us to tell computers exactly what we want them to do. I found this description of programming algorithms from Study.com useful:

You can think of a programming algorithm as a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal. We’ve all seen food recipes — they list the ingredients needed and a set of steps for how to make the described meal. Well, an algorithm is just like that. In computer lingo, the word for a recipe is a procedure, and the ingredients are called inputs. Your computer looks at your procedure, follows it to the letter, and you get to see the results, which are called outputs. A programming algorithm describes how to do something, and your computer will do it exactly that way every time.

So basically, an algorithm is just a series of very specific steps! See the below flowchart depicting an algorithm to fix a broken lamp. Note that this is a very simple algorithm; it could be improved! What if the outlet that the lamp is plugged into is burned out? This algorithm didn’t account for that, and buying a new lamp won’t help us if we’re plugging it into a burned out outlet! There are usually “edge cases” like this that you aren’t expecting.

How many software developers does it take to change a light bulb? I don’t know — that’s a hardware problem!

Secondly, what is the best way to solve algorithm challenges? I am a staunch advocate for the PEDAC method. PEDAC stands for Understanding the Problem, Examples/Test Cases, Data Structure, Algorithm, and Code. Notice how writing code is actually the last part of the process. I used to struggle with this. I wanted to dive right into algorithm challenges! There’s something exciting about hacking away, trial and error, frantic effort. But that’s wasted effort. It’s inefficient. The hardest part about algorithm challenges isn’t the actual writing of the code. It’s understanding how to break down a problem into steps that are specific and replicable. Think before you code!

Know that there is a light at the end of the tunnel. Despite how much I struggled with algorithms at the beginning, they’re now my favorite part of programming. When I went through Suncoast Developers Guild (a coding bootcamp in St. Pete, Florida), we practiced algorithm scripting almost daily. I was now learning the JavaScript methods necessary to solve the algorithms in class and applying them to the challenges. I was introduced to resources I didn’t know about before, like MDN. I was seeing algorithms for a second time and in a new light. I remember solving the first one on my own. It was such a high. I became addicted to them and known for practicing around campus with dry-erase markers on whiteboards and glass doors. There is literally a picture of me on the SDG website solving one!

Almost did this in Sharpie.

So overall, don’t lose faith! Plow through Imposter Syndrome! Just like everything else on your journey to becoming a software developer, some concepts will come easier than others! Keep working hard! You can do it!

Now, without further ado, here are the algorithm scripting challenges I have made posts for:

I hope you enjoy this series! You can follow me on Medium, LinkedIn, and GitHub!

--

--

Dylan Attal

Full stack web developer. Tampa native, coffee enthusiast, personal finance geek.