Basic JavaScript - Record collection

Hello,

I’m not sure how to fix this code:

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

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

Link to the lesson: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

Thanks!

Hello,

  • check your assignment operator .
  • You are assigning the value twice. Instead, you should use conditional logic to check if the property exists. If it does, push the value into the existing property. Otherwise, assign the value as a new property.

Thank you so much! It works now. :slight_smile:

1 Like

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