Swapping values

Tell us what’s happening:
Describe your issue in detail here.
why doesn’t my code work?

Your code so far


let a = 8, b = 6;
// Only change code below this line
const [a, b] = [6, 8];

Your browser information:

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

Challenge: Use Destructuring Assignment to Assign Variables from Arrays

Link to the challenge:

Your code should work even if someone changed the first line to use different values for a and b.

Also, you shouldn’t use const to re-declare a and b.

1 Like

but if we were to swap only these two specific values, it would work right?

No. You have hard coded two specific numbers. That doesn’t work in general. You need to switch the values in a and b without knowing beforehand what numbers are in there and hard coding the results.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.