Can someone help me?, I'm so lost

This keep showing up “ReferenceError: records is not defined” if I put records instead of recodCollection.

because you changed the first line right here:

The function call uses recordCollection, but the function signature and the body of the function use records.

This is what I got 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!=="" ){
recordCollection[id][prop] = value;
return recordCollection;
}else if(prop =='tracks'){
recordCollection[id][prop] = [];
recordCollection[id][prop].push(value);
return recordCollection;
}else if(prop =='tracks' && value!==""){
recordCollection[id][prop].push(value);
return recordCollection;
}else if(value ==""){
delete recordCollection.id.prop;
return recordCollection;
}


}

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

Still showing 3 errors.

First off, inside your function you should not reference the global recordCollection variable. You need to change all instances of recordCollection inside your function to records.

Like this?

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

}

return records;
}


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

Replace this

And this one

And this one

And this one

And this one.

There is no recordCollection inside of the function, only records

Aren’t you calling the record parameter instead of the object recordCollection ?

Referencing the records parameter, exactly!

Here’s the important part from the explanation about why you need to only reference the records parameter:

Note: A copy of the recordCollection object is used for the tests.

If you only update the recordCollection variable in the global scope, then all of the tests will fail. Each test passes its own recordCollection object into your function as the first parameter. They expect their object to be the one that gets updated.


Said another way: Record collection - removing properties - #4 by JeremyLT

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.