HELP Modify Array Data With Indexes

Tell us what’s happening:
hello!!!
could someone please help me understand what I am doing wrong and how to fix my problem with the
correct index

Your code so far


// Example
var ourArray = [18,64,99];
ourArray[1] = 45; // ourArray now equals [18,45,99].

// Setup
var myArray = [18,64,99];

// Only change code below this line.
correct index in myArray = [45,64,99];

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes

Take a look at the example code, this is the syntax used to modify an element in a given index. In this case it’s index 1.

You will be doing the same thing. You are changing a value at a index 0 to 45.

1 Like

I am still totally stuck

1 Like
// Example
var ourArray = [18,64,99];
ourArray[1] = 45; // ourArray now equals [18,45,99].

// Setup
var myArray = [18,64,99];

// Only change code below this line.

var ourArray = [18,64,99];
ourArray[0] = 45;

You need to modify myArray variable in the setup, instead modifying ourArray in the example.

2 Likes

yay that worked

1 Like

Okay so what we need to do is: Modify the data stored at index 0 of myArray to a value of 45 .
so 1st thing we set a variable and call it myArray and set it up like we ussualy do adding a = and a ; Then we need to input the numbers 45 64 and 99 we get those if we put just the 45 in the string alone.

var ourArray = [50,40,30];

just like in the above example they give us we start with bracets and end with them no spaces.

var myArray = [45,64,99];

now comes the second part again where we do use zero-indexing

> ourArray[0] = 15; // equals [15,40,30]

as we can see in the example above we don’t need to put a var before myArray only bracets and the standart set up we used before the first number is 0 cause again 0-indexing then 45 because thats what they asked us to do

myArray[0] = 45;