Background Information

In the next lesson, you'll see an important guide video on how to approach these exercise/solution sets.

Remember, "algoirthm" just another way of saying "a sequence of steps to accomplish a task" - i.e. a process. The vast majority of web applications are essentially functions working together. "Algorithm" is just another word for "function". And, in JavaScript, a function is essentially a block of code that can have an input and output. You should have a basic grasp of JavaScript functions as well as the fundamentals like strings, numbers, arrays, loops, conditionals, etc. before doing these exercises.

There are a few key characteristics to help you think about algorithms in JavaScript:

  1. You can use the function syntax to create an algorithm, and provide it with a custom name, much like a variable name. Again, you should have experience with JavaScript basics like functions, arrays, loops, etc. before doing these exercises.
  2. They have inputs and outputs. You can think of algorithms as black boxes, where you put something in, something happens to it, and then something comes out the other end.
  3. First you define the algorithm, by writing a function definition. The functions/algorithms can then be reused anytime simply by referring to the name and adding () next to it.
  4. Creating functions is essentially like coming up with your own language. It's a way to add to a programming language to get the computer to do custom behavior for you.

Here's a visualization of how an algorithm looks, conceptually. Notice it has an input and an ouput, with a sequence of steps in between:


Source: Wikipedia Creative Commons