Record Collection, pls help

Tell us what’s happening:
Hi everyone, I am currently in this challenge, but it doesn’t resolve the test

“After updateRecords(2468, "tracks", "Free") , tracks should have "1999" as the first element.”

I can see why other code to solve the problem works, but idk why mine doesn’t, can you explain me please?

Your code so far

// 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: [
    "Little Red Corvette"
1245: {
  artist: "Robert Palmer",
  tracks: [ ]
5439: {
  album: "ABBA Gold"

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

updateRecords(5439, "artist", "ABBA");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Record Collection

Link to the challenge:


I stuck some console.log lines in your function, and called the test that is failing.
You have two different if statements that are both running on this test, causing the incorrect output.

The error lies with collection.hasOwnProperty("tracks") == false. Can you see why? :slight_smile:

1 Like

Hi, you are fast haha…
Ok I think I see that error, the ‘hasOwnProperty’ method gives me the boolean alone, so I removed the “==false” and now that test is passed. But when I do that the test that adds a new Array goes wrong:
" After updateRecords(5439, "tracks", "Take a Chance on Me") , tracks should have "Take a Chance on Me" as the last element."
So, why the two different if statements run if they don’t share the same conditionals?

Because now you are checking if collection.hasOwnProperty("tracks"), which itself will never evaluate to true.

But it returns the boolean …what does it need to evaluate?

It evaluates whether collection has a property that matches "tracks" , and returns true or false.

collection does not have a property "tracks". :slight_smile:

OHHHHH hahahahaah
The collection itself doesnt have the property, but the id does. So…
in the if is correct. Thank you very much!

1 Like

Glad I could help~! Nice work! :smiley:

1 Like