How can I solve this step. I read someone stuck on same as step 24.
So I still didn’t know how to fix this lecture. Especially how to string to Mexico City.
Your code so far
let cities;
let cities;
cities = [ "London", "New York", "Mumbai" ];
cities = [ "London", "New York", "Mexico City" ];
array[2]
array[array.length - 1]
console.log(cities);
console.log(cities);
// User Editable Region
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn Introductory JavaScript by Building a Pyramid Generator - Step 24
you have modified your code. reset the challenge step and follow the instructions:
Start by declaring a cities variable and initializing it as an array of the strings "London", "New York", and "Mumbai". Then log that variable to the console.
After logging, change the last element of cities to the string "Mexico City", then log the cities variable again.
Could you tell me where is my mistake
let cities;
[ “London”, “New York”, “Mumbai” ];
console.log(cities);
let cities;
[ “Mexico City” ];
console.log(cities);
array[array.length - 1]
Could you tell me where is my mistake
let cities;
[ “London”, “New York”, “Mumbai” ];
console.log(cities);
let cities;
[ “Mexico City” ];
console.log(cities);
array[array.length - 1]
let cities declartion and [ “London”, “New York”, “Mumbai” ]; should be on one ine.
example like: let country = ["first", "second", "third"];
that is called declaration and asssigment.
remove the duplicate delaration of cities variable.
that is example array. change to actual array cities. then assign it
that string you have above.
put that console.log after your second assignment.
Hey @Shocean I see that you were struggling in this step as I did as well. Didn’t know if you had had your question answered even though hasanzaib had explained it well already. So here is how it made sense to me following the instructions given in the step… I’ll post them here.
1)Start by declaring a cities variable and initializing it as an array of the strings "London", "New York", and "Mumbai".
2)Then log that variable to the console.
3)After logging, change the last element of cities to the string "Mexico City",
4)then log the cities variable again.
When solving for Step 1) you must declare your variable. When you initialize a variable to an attribute like an array, you’re suggesting an equivalence between the objects thus when initializing your variable to an array which includes names of cities, you’d include an equal sign
let var = [“San Francisco”, “New York”, “Sacramento” ];
Step 2) Says log your variable. Log Cities.
Use Console.log(). You have it right above
To me Logging your variable is almost like solidifying its input.
Step 3) In this Step they have given you the universal equation for the array’s length.
array[array.length -1]
First, when using the equation above, you have to assign it to your particular array, do it by changing “array” to the name of your variable (cities). Then you must change the value of the last item in your array to “Mexico City”. Again this suggest that those values must be equivalent, thus make them equivalent
array[array.length - 1] = " New Value"
Step 4) solidify your new information. Log your variable. Use Console.log()
Put it all together
let var = [“San Francisco”, “New York”, “Sacramento” ];
Console.log();
array[array.length - 1] = " New Value" ;
Console.log();