Hi can you help me? why my solution doesn't work?

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

  **Your code so far**

// Setup
var 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(object, id, prop, value) {
if(prop !== "tracks" && value !== "") {
  object[id][prop] = value;
} else if (prop === "tracks" && (object[id].hasOwnProperty("tracks"))){
  object[id][prop] = [value];
} else if (prop ==="tracks" && value !==""){
} else if (value === ""){
  delete object[id][prop];
return object;

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

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36

Challenge: Record Collection

Link to the challenge:

You need to check if the record does not have a tracks property which you can achieve by doing this

object[id].hasOwnProperty("tracks") === false


else if (prop === "tracks" && (object[id].hasOwnProperty("tracks"))){
     object[id][prop] = [value];

Like mentioned above, you need to fix the condition to check if your object does not have a tracks property.

Also, I see some problem inside the code block of that condition.
If your object does not have a tracks property then you intialize a tracks array and add the value inside that array with the following line.

object[id][prop] = [value];

So, I’m just wondering why are you pushing that same value again in that array in the following line with this ?


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