Learn Introductory JavaScript by Building a Pyramid Generator - Step 24

Tell us what’s happening:

How can I update the last element of the cities array to the string “Mexico City”

Your code so far

let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];

// User Editable Region

let cities = [ "London", "New York", "Mumbai" ]
console.log(cities)
let cities = [ "London", "New York", "Mexico City" ]
cities[cities.length - 1] 
console.log(cities)

// User Editable Region

console.log(rows);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 24

With the let keyword you can only define elements the one time. You can’t re-reserve the same variable in memory. You were on the right track though with the reassignment.

Though if you wanted to, you could finish the array stuff and assign that position inside the cities array to "Mexico City". It’s up to you.

please can you explain in more details

Hi!

You have already declared cities variable and assigned it an array ["London", "New York", "Mumbai"].

Remove that second declaration and assignment of cities array.
And assign the string "Mexico City" to the last element cities[cities.length - 1] of cities array.

please can add more details to your explanation

Example

countries[countries.length - 1] = "Pakistan";

Above in the example, I have assigned "Pakistan" to the last element of the countries array.
For the challenge step, you need to assign the string "Mexico City" to the last value of cities array. Reset the challenge step and try again.