I'm trying my best but cant figure it out

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

const s = [5, 7, 2];
function editInPlace() {
 // Only change code below this line

 
const s = [2,5,7];
 // Only change code above this line
}
editInPlace();
console.log(s)
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64

Challenge: Mutate an Array Declared with const

Link to the challenge:

The first thing to fix is that you don’t want to declare a new array s inside of the function body because you want to update the global array s that is created above the function.

1 Like

Hi @damn_imgud !

Welcome to the forum!

Have a close look at the lesson example.

If I try to assign a new array to const like this then I would get an error .

const s = [5, 6, 7];
s = [1, 2, 3];

That is why you can’t do this in the challenge

But look at the third line of the example.

s[2] = 45;

This line of code tells us that we can assign 45 to the third element in the array.

Original lesson array

[5, 6, 7];

Revised array

[5, 6, 45]

Use the same method we just did from the lesson to change from [5, 7, 2] to [2, 5, 7]

Hope that helps!

1 Like

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