BETA freeCodeCamp -ES6: Mutate an Array Declared with const- possible bug report

Hello, my code:


"use strict";

const s = [5, 7, 2];
// change code below this line
s[0] = 2;
s[1] = 5;
s[2] = 7;
// change code above this line
console.log(s);

Result:
Do not replace const keyword. WRONG
s is declared with const. WRONG
Do not change the original array declaration. WRONG
s should be equal to [2, 5, 7]. GOOD

I don’t think my response is wrong.

Have a good day

1 Like

There’s an issue with the challenges that use the const keyword.

Ok thanks you. So exercice with const won’t work.

Seems to be working now. You and I have the same code and it works. Did you remember to add the editInPlace(); at the bottom of your code? Seem like you’re missing this part.

function editInPlace() {
  "use strict";
  // change code below this line
    s[0] = 2;
    s[1] = 5;
    s[2] = 7; 
    console.log(s);
  // change code above this line
}
editInPlace();```

The browser always seems to scroll away from the first line and that’s how I’ve been screwing up because I couldn’t see the variable being declared.

This is my version:
// change code below this line

s.unshift(s.pop());

// s = [2, 5, 7]; <- this is invalid

// change code above this line

This code actually works, but I’m trying to use a loop. Who has done that already? Would like to take a peek!!

That’s the method I used as well. First I did it by assigning each array the new value; but then I noticed that they were the same numbers, just the first number was now the last item, and the other two moved down. I first did this incorrectly, by doing s.push(s.shift());.

i tried something else.
var q=s.pop()
var r=s.unshift(q)
return r