I don't understand what is wrong at all

Tell us what’s happening:
I can’t pass all of the tests and there is no help video explaining what I am doing wrong.

Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0.

Challenge: Record Collection

Link to the challenge:

Hi and welcome to the forum.

You should not be referencing the global variable collection.

1 Like

Okay I will change that to object, yes?

1 Like

Hi Jeremy, I have this error now:

“After updateRecords(collection, 2468, “tracks”, “Free”), tracks should have 1999
as the first element.”


Assuming that you removed the reference to collection, as @JeremyLT suggested, then the problem is probably the fact that you are always setting the tracks property to an empty array before adding value.

// Only change code below this line
function updateRecords(object, id, prop, value) {
  if (value.length == 0) {
    delete object[id][prop];
  } else if (prop != "tracks") {
    object[id][prop] = value;
  } else if (prop == "tracks") {
    object[id][prop] = []; // Right here.... what happens if you already have a track?
  return object;

Isn’t that my empty array? Should I put this in a separate conditional statement?

You are missing

If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array

If the tracks already exist, you are supposed to add the new value to the end of the array. Right now you are always setting the tracks array to [] even if it already exists.

Oh okay. Now it’s making more sense.

Should I just object[id][prop] = [].push(value);?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

This would assign the number 1 to the tracks property, because push returns the length of the array. The point that Jeremy is trying to make is that you should not be removing the elements that are already in the tracks array (if there are any).


I will try it. I will also format my code like this:

<p>Hello World! </p>