fCC Wherefore art thou Challenge

The default challenge code declares a const array outside the area we are permitted to change in the code - it is above the line: // Only change code below this line and then returns that const array outside the area we are permitted to change in the code - it is below the line: // Only change code above this line

I get an error " TypeError: Assignment to constant variable. " → fCC Wherefore art thou Challenge - Forum Post - JavaScript - OneCompiler

I do recall a challenge in which we are taught that const can be modified: Mutate an Array Declared with const

Are we supposed to be going that direction with the challenge then? To go ahead and mutate the const array?

I notice that the code shown in the other posts related to this challenge declare the variable as var arr = [] (not const) - are they able to change the code above the line or has the challenge been changed?

One seems to completely remove the restrictions // Only change code below this line and // Only change code above this line as well as change the variable declaration var matchedObjectProps = []

But I don’t see any mention of variable declaration in any of them.

So are we able to change code outside the designated area then?

The Code Below Is The Unaltered Default Code Presented In The Challenge…

function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line


// Only change code above this line
return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

In Summary…


  • Are we supposed to change the variable declaration so it is not const?
  • Are we able to change code outside the boundaries (I’d like to know)?
  • Are we supposed to mutate the array as we were shown in a previous challenge?
  • Why is the array declared as var (not const) in other challenges but the challenge
    I am given gives me const?

  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0

Challenge: Wherefore art thou

Link to the challenge:

You can change the contents of an array declared with const, but you can’t change which array the variable points to.

We did a sweep through the challenges and removed the use of var because it is a legacy feature and generally shouldn’t be used.

You can change code outside of those comments if you are careful to not break the assumptions of the tests, but you never need to do so.

1 Like

Ok thanks

Did you see my edit to my post? Which question(s) did I miss?

1 Like

Yes, and I edited my response as well. Just wasn’t fast enough :slight_smile:

1 Like