Basic JavaScript: Record Collection(18 March 2020)

Dear Campers,

I could use a bit of feedback on getting started on this assignment. Here is the code:

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

  return collection;

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

I’m not sure if I’m starting my ‘else if’ statement correctly. The instructions says:

If prop is "tracks" and value isn’t empty ( "" ), push the value onto the end of the album’s existing tracks array.

I followed accordingly and coded thus.

I appreciate any constructive feedback. Thanks , Campers. Please feel free to ask me anything regarding my code so far.

Explain what you think this is checking and how it helps you solve the challenge.

1 Like

It’s checking if the property “tracks” is not empty. Is that right?

Look carefully at the collections object. What properties does it currently have? Can you list the property names of the collections object? Hint: There are 4 of them.

1 Like

(1) The ID number
(2) Album
(3) Artist
(4) and Tracks?

Nope. The 4 property names of the collections object are 2458, 2468, 1245, and 5439. The corresponding values of each property name is an object containing other properties. This means you are dealing with nested objects here.

1 Like

if updateRecords(47384384, "unnamed", "") was a new update, and the collection had a "unnamed" : ["random name"]; then when updateRecords runs, should return a new unnamed : "";

if (updateRecords[id] == “tracks” && updateRecords[id] != “”) {

Thanks for the input. I’m not quite sure what I’m missing. Does the parameter ID access the 4 property names? In my code above, I’m checking if each ID has the object, “tracks” and is not an empty array. Does my push method belong in this if statement?

updateRecords is the function. Why are you trying to reference an id property of a function? You should be referencing the id property of the collection object.e