Record Collection - Code Review, Please?!

Tell us what’s happening:

After  `updateRecords(5439, "tracks", "Take a Chance on Me")` ,  `tracks` should have  `"Take a Chance on Me"` as the last element.
After  `updateRecords(1245, "tracks", "Addicted to Love")` ,  `tracks` should have  `"Addicted to Love"` as the last element.
After  `updateRecords(2468, "tracks", "Free")` ,  `tracks` should have  `"1999"` as the first element.

Is this because I am not checking for new objects ?

Your code so far

function updateRecords(id, prop, value) {
  if (value == "") {
    delete collection[id][prop];
    return collection;

  if (prop != "tracks") {
    collection[id][prop] = value;

  if (collection[id][prop]) {
    collection[id][prop] = value;

  } else {
  return collection;

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12105.47.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.54 Safari/537.36.

Link to the challenge: text will be blurred

Nothing is happening for when prop === "tracks" because that code block is entered only for prop != "tracks" (careful with where parenthesis are)

Remember that the “tracks” property is an array, of you just do collection[id][prop] = value than “tracks” property is no more an array

Also, I read a "if the property has a truth value, set it to value, if the property has a falsy value, push value to it. Which doesn’t work if it is not an array, you can’t push to something undefined

1 Like