Skip to main content
Version: v1.1

✏️ 1.3.1.5 Practice: Looping

Goal: In the Looping lesson, we learned:

  • How to use an Array.prototype.forEach() loop.
  • Naming conventions for arrays and the parameter in a loop.

As we can see, looping is an incredibly important programming concept. Now it's time to practice. We'll begin with two looping exercises in the console and then move on to creating a small project.

Warm Up


  • If we used Array.prototype.forEach() to loop through an array called "kittens", what should we call the parameter in the Array.prototype.forEach() function? Why?
  • What does the += operator do?

Code


Complete both of the exercises listed below.

Looping Practice in the DevTools Console

  • Make an array of your friends' names. Loop through it and console.log() a greeting to each friend in the array.
  • Write a loop to multiply an arbitrary amount of numbers. This should look similar to the code to sum numbers from the "forEach Looping" lesson.

Favorite Ice Cream Flavors

  • Make a web page that lists out your favorite ice cream flavors. Rather than writing the flavors in the HTML, use a JavaScript loop to insert the flavors into the page from an array. Use the document.createElement() and Element.append() or Element.prepend() methods to create and add elements to your webpage.