Could use Help with Record Collection Challenge

Tell us what’s happening:
I am currently working on the Record Collection challenge. I am just a little confused why I get this error with the code I have written so far.
TypeError: Cannot create property ‘prop’ on number ‘5439’
I am using id.prop = value; to update the object and as far as I can tell I am updating the object correctly but the error I am getting seems to suggest I am not. Any pointers on why I am getting error? Am I not updating the object correctly?

  **Your code so far**

// Setup
var 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.length > 0) {
 
}
id.prop = value;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

A value will not always be something that has the .length property. A number, for example, doesn’t have a length.

is the a better way to test the length of a string then?

The value will not always be a string.

But you don’t need the length. What is the string that you really need to check for?

id is not an object, it is a number
check again, what’s the object? use console.log to be really sure

should it be recordCollection.prop = value; ?

What should be recordCollection.prop = value? You shouldn’t reference the global variable recordCollection at all. Also, you can’t use dot notation with property names stored in a variable.


You are trying to be a bit too fancy.

Your instruction says

If value is an empty string, delete the given prop property from the album.

Here is a test case

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

What is the absolute simplest way to check if you have an empty string for the value?

well, recordCollection is an object, but remember you need to always use function parameters when they are there

also, you can’t use dot notation with variables

and, what are the properties of the recordCollection object?
it doesn’t have tracks or artist properties

I honestly don’t know the simplest way to check for an empty string. I though I was doing that.

How do you check if a variable holding a number is equal to 5?

with the equality operator? ==

I’d use === instead of == (super important in this case), but yep.

So, using that same idea, how do you check if a value is an empty string ("").

I think I see, value === “”;

1 Like

Bingo! In that case, you bypass the whole problem where value is not a string.

would I want to use !== “” because the instructions say if value isn’t an empty string, update or set that album’s prop to value .

1 Like

Yeah, that makes sense. (Hint: you might get a simpler solution if you handle the 5 bullet points in a different order though)

Do I need to create those properties then?

no, look at the structure of the object, what are the properties of the object, what does have the tracks and artist and other properties?

Tell us what’s happening:
I’m at a point where I am confused why my solution for this challenge is not working. It seems to me if I go through each of the criteria for the challenge they all work but when I run the test it wont accept my solution. Am I missing something? I have not looked at the solutions in the hints. I am trying to figure this out on my own but i’m not sure why my solution does not work. Thanks for your feed back.

  **Your code so far**

// Setup
var 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" && value.length == 0) {
   records[id][prop] = [value];


} else if (prop === "tracks" && records.hasOwnProperty(prop)) {

    records[id][prop].pop(value);


} else if (value === "") {

  delete records[id][prop];

}

}
updateRecords(recordCollection, 5439, "artist", "ABBA");
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
updateRecords(recordCollection, 2468, "tracks", "Free");
updateRecords(recordCollection, 2548, "tracks", "");
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

check this really carefully