Record Collection stuck

Record Collection stuck
0.0 0

#1

Tell us what’s happening:

Hey friends!

Well… I have been stuck a couple of hours in this problem. I have tried to express in coding the given instructions, but my code is not working.

Your code so far

function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== ""){
   return collection;
  } else if (prop === "tracks") {
    collection[id][tracks].push(prop);
    return collection;
  } else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false) {
    var tracks = [];
    collection[id][tracks] = prop;
    return collection;
  } else if (prop === "artist" && collection[id].hasOwnProperty("artist") === false) {
    var artist = [];
    collection[id][artist] = prop;
    return collection;
  } else if (prop ==="") {
    delete collection[id][prop];
    return collection;
  }
}


// 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": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  
  
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

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


#2

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3
var myPlants = ["ficus", "oak", "maple"];

I get it!
Thank you!


#4

Ok folks.

Finally, I reach the solution.

Merci également.