Use Destructuring Assignment to Assign Variables from Arrays - Testing the Wrong Thing

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. :smiley:

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:

1 Like

Using const [a,b] = [b,a] is wrong: it introduces new variables a and b that shadow the ones in global scope, so it actually has no effect at all.

Edit: I see what you mean: const is being used in the example text, not your solution, and is therefore confusing people – you’re not the first to mention it. Sorry about the confusion.

I’d recommend opening a bug on github about this issue, since posting on the forum isn’t likely to lead to much action. Definitely do keep pointing out issues with the example text though – FCC is in sore need of more input from education professionals.