Goal: In the Looping lesson, we learned:
Array.prototype.forEach()
loopAs we can see, looping is an incredibly important programming concept. Now it's time to practice. We'll begin with several looping exercises in the console and then move on to creating and updating small projects.
Array.prototype.forEach()
to loop through an array called "kittens", what should we call the parameter in the Array.prototype.forEach()
function? Why?+=
operator do?console.log()
a greeting to each.Refactor your Mad Libs page we created in this exercise to use a loop.
In the Introduction to jQuery lesson we created a web page that triggered alerts containing information about a particular HTML tag whenever a user clicked on an HTML element. Try to refactor this page's multiple, similar event listeners using a loop.
Note: When choosing a name for the variables in your loop, it's good practice to use a plural for the array and the singular form of that word for the loop.
> const languages = ['HTML', 'CSS', 'JavaScript'];
> languages.forEach(function(language) {
alert('I love ' + language + '!');
});
The array is named languages
and the parameter is the singular language
.
Lesson 15 of 34
Last updated January 11, 2021