Plz help me Use Destructuring Assignment to Assign Variables from Arrays

My code is not working can any body help me?

Your code so far


let a = 8, b = 6;
(() => {
  "use strict";
  // change code below this line
  const[b,a]=[a,b];
  // change code above this line
})();
console.log(a); // should be 6
console.log(b); // should be 8

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays

You shouldn’t use the const keyword in this case, because you want to manipulate the existing a and b variables, not make new ones.

5 Likes

Thanks so much!
I solved my problem .

1 Like

I was doing the same thing, thanks for creating this topic on the forum. Helped me a bunch.