Need help direction please

Tell us what’s happening:

Your code so far


const s = [5, 7, 2];
function editInPlace() {
 'use strict';
 // Only change code below this line
s = [2, 5, 7];
 // Using s = [2, 5, 7] would be invalid

 // Only change code above this line
}
editInPlace();

Your browser information:

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

Challenge: Mutate an Array Declared with const

Link to the challenge:

Hello~!

Take a look at the example provided in the challenge instructions:

"use strict";
const s = [5, 6, 7];
s = [1, 2, 3]; // throws error, trying to assign a const
s[2] = 45; // works just as it would with an array declared with var or let
console.log(s); // returns [5, 6, 45]

Do you see the line that successfully changes one of the values in the array?

You need to change every place in array separetely.

just thinking of how to apply it here

Okay, so let’s look at the expected return value:

s should be equal to [2, 5, 7].

If s[2] = 45 sets the last value of the array to 45, how would we set these three values?

thanks
but still couldn’t get it
this is what i did
s = [2, 5, 7];
but it is not passing the text yet

you can’t do this. it literally says that s = [2, 5, 7]; will be invalid. you need to change every place in array separately as they did in the example using s[2] = 45 (they changed the 3d element there, so you can use the same process and change all the numbers in your array)

1 Like

has gotten it finally
thanks for your concern

1 Like