Record Collection - Dot Notation

Tell us what’s happening:
Describe your issue in detail here.

Okay I just completed the record collection challenge, this post is more me seeking understanding than a solution to a problem . I wrote my code according to the instructions using dot notation and it didn’t test successfully but when I checked the solutions on the hint page and switched to bracket notation as used in the solutions it was successful. I feel like I might be missing something really simple here but could someone please explain why it is so?

  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Hello there,

It might help others better help you, if you shared your original code that you expected to pass.

Otherwise, I typically link this description: Confused about "" and [] when calling property - #4 by Sky020

Hope this helps

I believe this was my initial code:

function updateRecords(records, id, prop, value) {
  if (prop!=='tracks' && value!=="") { = value;
  } else if (prop==="tracks" &&"tracks")===false) { = [];;
  } else if (prop==="tracks" && value!=="") {;
  } else if (value==="") {
  return records;

Thanks, for sharing that.

So, the link I pasted above does explain the difference. In your case:

id is a variable (in this updateRecords function it comes as a parameter). So, is prop. looks for the property id in the object literal records. Here is an example of the object literal records:

var records = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']

This object literal does not have the property id. So, trying to access yields undefined. Same goes for id.prop - does not exist, therefore id.prop does not exist.

Think about what happens when the code is compiled:

const myObj = { 1234: { someProp: "some val" } };
const obj2 = { id: { otherProp: "val 2" } };
const id = 1234;
console.log( // undefined
console.log( // { otherProp: "val 2" }
console.log(myObj[id]) // You test this, and see what happens

Hope this clarifies. If not, be sure to ask specific questions we can work through.

1 Like

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