Freecodecamp: Record collection > feels like steep learning curve

Created on 20 Apr 2016  路  10Comments  路  Source: freeCodeCamp/freeCodeCamp

Hi All,

Not sure if this is the right place to put this, or even how to put this properly: I have been making my way through FreeCodeCamp and all the exercises up until Record Collection have been built with a steady progression of knowledge and have been very do-able, with all needed knowledge presented in previous exercises.

My issue is that to complete this exercise, double brackets need to be used, for instance

 collection[id][prop] = value;

I went back and checked various exercises (the 20 before this, and doing a search for "brackets" for all exercises) and I didn't see a mention of double brackets, so I didn't know double brackets were possible and none of the previous exercises seemed to lead me to that train of thought. The only way I was able to complete this exercise was jumping onto gitter and having someone tell me explicitly to use collection[id][prop]. I was able to write all the other parts of the code and work through the logic mostly by myself except for the double brackets part.

I guess i'm just suggesting a note, hint, or exercise on double brackets somewhere before this exercise might be useful as there was no other way for me to know double brackets were possible without the help of others in gitter.

Thank you very much for your time and sincere apologies if this isn't the proper place for this message,
Allen

Challenge Record Collection has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
   if ((value !== "") && (prop !== "tracks")){
     collection[id][prop] = value;
    } else if ((prop == "tracks") && (value !== "")){
      collection[id].tracks.push(value);
    } else if (value === ""){
      delete collection[id][prop];
    }
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");


help wanted learn discussing

Most helpful comment

It might make sense to have another challenge called "Nested Objects" that explicitly shows the double bracket notation.

All 10 comments

@allenhsieh Thanks for reporting this.
You can also discuss this more in the Curriculum Development Chat room.

@SaintPeter this one needs your expertise I believe.

/cc @FreeCodeCamp/issue-moderators

I agree that it is explicitly mentioned that double brackets are "legal." There is one lesson that does use this double bracket notation, but it is with multi-dimensional arrays.

I guess it is implied in this lesson that with the first bracket, you get the array. Then with another set of brackets, you're able to access the next level. This confusion might stem from this is on an array nested within a JavaScript object, rather than an array within another array.

For this lesson, I guess it wouldn't hurt to mention that you can access elements within arrays nested within JavaScript objects with double brackets.

It might make sense to have another challenge called "Nested Objects" that explicitly shows the double bracket notation.

So we add a challenge and a hint in this challenge to refer that? That should solve the confusion.

I just noticed this issue - it's a great point. This particular challenge does seem to throw many people for a loop. Good to know that it is getting some attention. I was also trying to develop a better explanation or description of the problem, thinking that some people just didn't grasp the concept of a "record collection" or "album collection" and what they were supposed to be trying to achieve with the code?

It definitely feels that there has to be another stepping stone before this. If it help at least half of the people who get stuck with this, it will be worthwhile!

I personally felt like this was the first real stump in the curriculum.
The link to the exercise under the "Note" heading does not show that you can chain brackets for a similar 'Drill-down' effect to the dot notation.
I think there needs to be another exercise prior to this one outlining the utility of "myObj[prop][subProp]".

I am happy to work on this and add a exercise on multidimensional arrays and objects if people think this needs to be changed. What do you think @SaintPeter

Just my two cents from helping people in Gitter with this problem:

It seems that students are not understanding that obj[key] is being resolved/boiled down into an actual value and instead is just some sort of magic. If instead of just showing them obj[key][otherKey], I think it would be more effective if we showed them that to our computer obj[key] is a value, just like obj is.

I am not sure if equality is taught before obj[key] is but perhaps showing that the nested object is equal (literally equal, not equivalent) to obj[key] will help drive the point home that we are grabbing a value and then grabbing a value from that value.

I found the Record Collection challenge more difficult because a few challenges before it, the Accessing Nested Objects challenge would not accept the following code:

Accessing Nested Objects challenge gives multiple warnings that both ['car'] and ['inside'] is better written using dot notation

Which fails a test case with...

Use dot and bracket notation to access myStorage

I had to open the Chrome console just to make sure that multiple bracket notation was still valid Javascript. But this mindset led me to start the Record Collection challenge with a bunch of collection.id.prop instead of collection[id][prop] thinking the latter was bad coding form. Unfortunately, the only error I got from the FCC console was:

TypeError: Cannot set property 'prop' of undefined

which led me to playing around in the Chrome console again accessing objects via different dot/bracket notations.

Thanks for your feedback, everyone. We've moved Record Collection to the advanced algorithms section.

Was this page helpful?
0 / 5 - 0 ratings