Build a Record Collection - Build a Record Collection

Tell us what’s happening:

Hello again, after a few crisis I solved the lab.

But I don’t understand why. My problem was the following code:

(prop === "tracks" && value !== "" && !records[id].hasOwnProperty("tracks"))
// Type error: .hasOwnProperty is not a function.

(prop === "tracks" && value !== "" && !records[id].hasOwnProperty(`tracks`))
// Then I changed "tracks" to `tracks` and I passed all tests.

I thougth there is no difference between ““ and `` in a string, isn’t it?

Why is .hasOwnProberty with `tracks` a function but with “tracks” not?

Edit: If I change my code in VS Code it still says .hasOwnProberty is not a function whether with ““ or ``.

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Record Collection - Build a Record Collection

Can you share the full code?

const recordCollection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    artist: 'Robert Palmer',
    tracks: []
  },
  5439: {
    albumTitle: 'ABBA Gold'
  }
};


const updateRecords = (records, id, prop, value) => {

   if (value === "") {
    delete records[id][prop];
    return records;
  } else if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;
    return records;
  }

   else if (prop === "tracks" && value !== "" &&    !records[id].hasOwnProberty(`tracks`)) { 
    records[id][prop] = [];
    records[id][prop].push(value);
    return records;


  } 
  
  else if (prop === "tracks" && value !== "") {
    let update = records[id][prop];
    update.push(value);
    return records;
  }
};

console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"));

I think this typo is the problem.

.hasOwnProberty is not a function

Sorry I don’t get it. If I write hasOwnProberty the “O” is large uppercase. After copying in the code it says “.hasOwnProberty is not a fuction”

But if I copy .hasOwnProberty from another user code, it works (e.g. Build a Record Collection - Build a Record Collection ).

What’s the difference between his and my code?

Edit: Okay I see. Property is written with p :smiley: English my friend..

Thank you for your help! :slight_smile:

1 Like