Learn
Loops
Repeating Tasks Manually

Before we write our own loops let’s take a moment to develop an appreciation for loops. The best way to do that is by showing you how cumbersome it would be if a repeated task required you to type out the same code every single time.

Instructions

1.

Create the variable vacationSpots, and assign its value to an array of three strings naming places you’d like to visit.

2.

Next, console.log() each item in vacationSpots. Since we don’t know loops yet, we have to console.log() each element in the array separately.

3.

Nice work! Now imagine that the vacation list had 100 places on it— logging each array element to the console by hand would be a tedious task! In the next exercise, we will learn how to make things more efficient with for loops.

Folder Icon

Take this course for free

Already have an account?