Record Collection Solution

Tell us what’s happening:
Hi. I can’t understand why this solution isn’t working. And can’t understand the logic of the solution from hint. Can someone explain it to me, please?
Your code so far

// 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: [
    "Little Red Corvette"
1245: {
  artist: "Robert Palmer",
  tracks: [ ]
5439: {
  album: "ABBA Gold"

// Only change code below this line
function updateRecords(id, prop, value) {
if(value === "") {
delete collection[id][prop];
} else if(prop !== "tracks" && value !== "") {
collection[id][prop] = value;
} else if(prop === "tracks" && value !== "") {
} else if(prop === tracks && collecion[id].hasOwnProperty(prop) === false) {
collection[id][prop] = [];

return collection;

updateRecords(5439, "artist", "ABBA");

Your browser information:

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

Challenge: Record Collection

Link to the challenge:

let’s try to run this function call that is giving you issues:
so I delete the function call that is present in the editor, and substitute it with the function we want to test:

 return collection;

-updateRecords(5439, "artist", "ABBA");
+console.log(updateRecords(5439, "tracks", "Take a Chance on Me"))

now we should see what the result is, but, oh, there is an error! It says
TypeError: collection[id][prop] is undefined
so it means that the function stops running somewhere.

I am going to use JavaScript Tutor to check where it stops

it stops at

} else if(prop === "tracks" && value !== "") {

it means that there is something wrong in this line or above it.

have we ever defined collection[id][prop]? actually, no, we are trying to push to an array that doesn’t exist, and we can’t do that.
Remember that the first statement in an if-elseif-else chain is the one that is executed, that means that the one after this where an array is created, is never reached as far as prop === "tracks" && value !== "" is true

1 Like

OMG Thank you so much! I’m so inattentive!