Stuck at 'For loops' and array!


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]);


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


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