Collection solution

Getting no progress on solving,

Here are the requirements

You start with an updateRecords function that takes an object like collection , an id , a prop (like artist or tracks ), and a value . Complete the function using the rules below to modify the object passed to the function.

  • Your function must always return the entire object.
  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.

Note: A copy of the collection object is used for the tests.

Here is my solution with 0 successes… Help

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

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

Anything would be super helpful.

1 Like

You are referencing collection, but an object (object) representing collection is passed to the function. You should be using it instead.

You are also attempting to reference a method named hasOwnValue which does not exist. Also, you reference a variable named condition which does not exist. There is at least one more issue with your code, but I will leave it to you to figure those out.

Haha, Jeez. Thank you! meant to put Property instead of value and Collection vs condition. crazy what you don’t see after staring at something for so long. very helpful thank you.