Please tell, why my code isn't passing tests

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

  **Your code so far**

// Setup
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'
}
};

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


return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

You hould have another look at this. What do you want it to do?

Why are you using recordCollection here? Is this correct?

Updated my code still not passing tests.

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'

  }

};

// Only change code below this line

function updateRecords(records, id, prop, value) {

    if (value === "") {

      delete recordCollection[id][prop];

    }else if (prop === "tracks") {

      recordCollection[id][prop] = recordCollection[id][prop] || [];

      recordCollection[id][prop].push(value);

    }else {

      recordCollection[id][prop] = value;

    }

  return records;

}

updateRecords(recordCollection, 5439, 'tracks', 'ABBA');

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

I reiterate this question

I don’t understand why you’re asking this.
I am using “recordCollection” cuz the object in which I have to make changes is recordCollection.

no, that is an example object. The function receive the object to change as one of its parameters

I didn’t get what you are trying to say.

here I am trying to push passed “value” to the end of array as question say’s
“add value to the end of the album’s existing tracks array.”

Id, props and value are all parameters of your function. Take a look at which parameter you are not using.

there is one more parameter which is “records”

I am using “recordCollection” as value for record.

still didn’t get what you’re trying to say.

Compare how you are using the other parameters, with how you are using recordCollection inside your function.
For example props inside the function is used to refer to in this case ‘track’. Is there a difference in the way you are using recordCollection compared to this?

finally passed all the tests.
Thankyou so much for your valuable time

1 Like