Tell us what’s happening:
While I was able to get this working eventually, I was disappointed to discover that, rather than testing my understanding of how destructuring can be used to assign variables from arrays, it appears to actually be testing my understanding of variable scope. I correctly understood that assignment could be switched using [a,b]=[b,a]
, however, it did not work because I included const
from the example. That issue should be explicitly taught rather than taught via testing. The coding challenge should focus on destructuring rather than scope. I say this as an expert on training and curriculum design, not just as someone complaining.
Also, not sure if this is something I should drop on GitHub somewhere, or if it should be placed here first.
Your code so far
let a = 8, b = 6;
(() => {
"use strict";
// change code below this line
[a,b] = [b,a];
// 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
.
Link to the challenge:
javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays