Freecodecamp: Variable should be defined as 'let' not 'const' because it is changing.

Created on 3 Mar 2017  ·  3Comments  ·  Source: freeCodeCamp/freeCodeCamp



Use the Spread Operator To Evaluate Arrays In-Place


https://beta.freecodecamp.com/en/challenges/es6/use-the-spread-operator-to-evaluate-arrays-inplace

Issue Description


The arr2 variable is defined as a const, but is supposed to be able to be redefined in the exercise.

Browser Information

  • Browser Name, Version: Google Chrome, Version 56.0.2924.87 (64-bit)
  • Operating System: OS X El Capitan 10.11.6
  • Mobile, Desktop, or Tablet: Desktop

Potential Solutions


There are 2 options to fix this challenge:

  1. Remove the // change code below this line and // change code above this line so that the user can add the solution ...arr1 directly into arr2 instantiation.
    Solution would be:
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
const arr2 = [...arr1];
  1. Change the initial instantiation of arr2 to: let arr2 = [];
    Solution would be:
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2 = [];
// change code below this line
arr2 = [...arr1];
// change code above this line

Both of these solutions currently pass the given tests. I want to clean up this exercise so its easier to understand for users.

Most helpful comment

@Ethan-Arrowood Nice catch!

Actually, this is solvable as it is - but this is most likely the intended way... :smile:

copy-contents-of-array

I suggest that we slightly change the format of the challengeSeed to solve this:

const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];

const arr2 = [];  // Change this line.

arr1.push('JUN');
console.log(arr2); // arr2 should not be affected

All 3 comments

@Ethan-Arrowood Nice catch!

Actually, this is solvable as it is - but this is most likely the intended way... :smile:

copy-contents-of-array

I suggest that we slightly change the format of the challengeSeed to solve this:

const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];

const arr2 = [];  // Change this line.

arr1.push('JUN');
console.log(arr2); // arr2 should not be affected

And I think we should add the hint to use the .push() function. Or hint to using something from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array .
I'll go ahead and make this change this evening.

@Ethan-Arrowood we are removing MDN links in favor of having a hints feature for the challenges than simply pointing to a resource that users may find a bit daunting while learning.

Nevertheless thanks a lot for the issue, and your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuincyLarson picture QuincyLarson  ·  3Comments

danielonodje picture danielonodje  ·  3Comments

imhuyqn picture imhuyqn  ·  3Comments

ar5had picture ar5had  ·  3Comments

robwelan picture robwelan  ·  3Comments