Stuck at 'For loops' and array!


#1


https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/2/3?curriculum_id=506324b3a7dffd00020bf661#


I want to print a new city name in each line but it doesn't happen so. How should I do that?


// Let's print out every element of an array using a for loop

var cities = ["Melbourne", "Amman", "Helsinki", "NYC", "Seattle"];

for (var i = 0; i < cities.length; i++) {
    console.log("I would like to visit " + cities[1]);
}


#2

you can replace the 1 in the cities[1] with i, which increases by one every time the loop iterates, printing a new value each time


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.