← Back to all posts
Intro to Arrays

Can I get some help with the last exercise pls! I don't understand why is it still wrong.

function exerciseFour(citiesArray){
// Exercise Four: In this function you will be given an array called 'citiesArray.
// re-assign the fourth city in the array to 'Santa Fe'.
// Note: DO NOT create a new array in this challenge.
// Note: Remember that array indecies start at 0.

exerciseFour[4]="Santa Fe";
console.log(exerciseFour [4]);

// Complete your work on the line above.
return citiesArray;
} exerciseFour();

https://repl.it/student/submissions/6895131

Answered by mwilki7 (283) [earned 5 cycles]
mwilki7 (283)

You have the correct logic, just incorrect syntax.
You are correct that you want to modify the 4th element of something
`exerciseFour[4]="Santa Fe";`

Remember "exerciseFour" is the name of the function so it is not an array.
citiesArray is the array you want to change the 4th element.

Take careful note of this comment:
`// Note: Remember that array indecies start at 0`
citiesArray[0] is the 1st element
citiesArray[1] is the 2nd element
citiesArray[2] is the 3rd element
citiesArray[3] is the 4th element

So we want to change citiesArray[3] because it is the 4th element.

You also had the correct logic for how to set the array element to 'Sante Fe'
All we need to do is replace exerciseFour[4] with citiesArray[3]:
`citiesArray[3] = 'Santa Fe';`

skudeva (16)

@mwilki7 Great! So I wasn't totally wrong 😁. Thank you!