Write an array and set it equal to a variable named vacationSpots. Inside of this array, list three places you'd like to visit


#1

Write an array and set it equal to a variable named vacationSpots. Inside of this array, list three places you'd like to visit(I DON'T UNDERSTAND THIS!)
My code is:

var vacationSpots = [1, 2, 3];

for (var i = vacationSpots.length -1; i >= 0; i--) {
	console.log('I would love to visit ' + vacationSpots[i]);
}

var vacationSpots = ['Dubai', 'America', 'India'];

#2

var vacationSpots = [1, 2, 3];

for (var i = vacationSpots.length -1; i >= 0; i--) {
	console.log('I would love to visit ' + vacationSpots[i]);
}

var vacationSpots = ['Dubai', 'America', 'India'];

// result
I would love to visit 3
I would love to visit 2
I would love to visit 1

You need only one array:

var vacationSpots = ['Dubai', 'America', 'India'];

for (var i = vacationSpots.length -1; i >= 0; i--) {
	console.log('I would love to visit ' + vacationSpots[i]);
}

// result
I would love to visit India
I would love to visit America
I would love to visit Dubai

#3

thanks for your help.


#4

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