Basic JavaScript - Record Collection

Tell us what’s happening:
Hey,
After a while of figuring this out, I am still stuck with one error:

“After updateRecords(recordCollection, 2548, "artist", "") , artist should not be set”

For some reason, I can’t get to fix this one and complete the task.
Any ideas why?

Thanks

Your code so far

// Setup
const recordCollection = {
  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(records, id, prop, value) {
   if (prop !== "tracks" && "value" !== ""){
       records[id][prop] = value;
  } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
    records[id][prop] = [value];
  } else if (prop === "tracks" && value !== "") {
      records[id][prop].push(value);
  } else if (value === "") {
    delete records[id][prop];
  }
  return records;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

I don’t think this quite doing what you think.

Here are the instructions of the challenge, according to the second line of the instructions, if (prop !== “tracks” && “value” !== “”){ is supposed to be done this way, no? or am I missing something.

  • Your function must always return the entire record collection 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.

I can read the instructions, lol. I’m trying to get you to read your code.

What does this say, in words?

Does it match what you did on this line:

Oh man that was the reason!
Thanks!!

1 Like