Record Collection - no idea where to start

I can but that was what I was trying to do with that code. That’s what the && value != "" bit was for.

So I’m confused because I was trying to do that already. I’m not sure how else I could check that.

1 Like
2 Likes

This is another way, Ella. You should come back to this

1 Like

Well, the condition I pointed you to does handle the “album doesn’t have a tracks property” situation.

Don’t worry about it though - I should really let you code this the way you want to code it.

I noticed that you’re now replying to three people on this thread, which is a lot of “voices” if everyone responds.

So I’m just going to make a couple of comments on the code you posted, and then I’m going to step out for a while.
I’ll check back a little later though to see how you’re getting on and, obviously, I’ll respond if you reply to my post.

Look back at how you accessed the album in your first if statement.
You need to get hold of the “tracks” property.
Then you can push value into that array.

Just take some time to think it through.

I’ll check back later to see how you’re doing.

1 Like

Oh. Yeah, I should have thought of that. :sweat_smile:

Thanks for the link!

3 posts were split to a new topic: Record Collection help kuba

I’ve got this now. But I can’t work out how to say ‘if tracks hasOwnProperty is false, then do this’. I did look at the other lesson but I don’t remember how to solve it or even understand it now.

I think I’m going to redo a lot of earlier lessons because I don’t feel like enough about JavaScript has stuck in my head to solve this.

// Only change code below this line

function updateRecords(records, id, prop, value) {

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

recordCollection[id][prop] = value;

}

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

tracks.push([] + value);

}

else{

return records;

}

}

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

id is a number. It can’t have a property. I think you want the record object associated with this id. How do you get that? you did it in the case above this one


You shouldn’t reference the global variable at all. You should only use the function arguments.

Okay now I have this. The one tick I had for solving at least one lesson condition is gone so I guess I messed the code up more.

Still don’t know how to say 'if “tracks.hasOwnProperty is false do this” which I think has to be important. I’m going though some of the earlier lessons to see if I work anything else I’m missing, but so far I still don’t know how to solve this.

// Only change code below this line

function updateRecords(records, id, prop, value) {

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

records[id][prop] = value;

}

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

tracks.push([] + value);

}

else{

return records;

}

}

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

tracks" is a string. It won’t have a property either.

You have to use the syntax some Object.hasOwnProperty(somePropertyName)

What is this? In words, what data does this represent?

Okay I have this now and it isn’t using a string for hasOwnProperty.

I thought it represented the record, record Id and the prop data.

I’ve been trying to access prop to make this work for the past 4 days. Apparently that is the key to everything but I cannot work out how to do it. It is very frustrating that I cannot grasp this.

// Only change code below this line

function updateRecords(records, id, prop, value) {

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

records.prop = value;

}

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

tracks.push([] + value);

}

else{

return records;

}

}

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

Closer, but this won’t work either. Does the object holding all of records ever have the "tracks" property?

This challenge is 100% about understanding what records, id, prop, and value mean.

What is records?

What is records[id]?

What is records[id][prop]?

How about you do this?
Try to understand what these mean:

  1. records,
  2. id,
  3. prop, and
  4. value

in comparison to the passed arguments which are

  1. records === recordCollection (can’t change except if it’s another object which is intended to be passed as argument)
  2. id === 5439 (it can be 5440, 5441…)
  3. prop === artist (can be ‘tracks’…)
  4. value === ‘ABBA’ (the value of prop).

If it’s understood to this point, then, the focus should be on accessing it, then.

Records - I don’t know. I was just using it because it seemed to be important. I can’t see it anywhere in the earlier Javascript and it seems to just exist as part of update records, I don’t know what it means or dose.

id = those numbers identifying the individual records.

Prop= artist, tracks, albumTitle.

Value - just got told it’s the string attached to prop.

I have this now but it’s still wrong.

function updateRecords(records, id, prop, value) {
if (id.prop != tracks && value != "") {
id.prop = value;
}
else if (id.prop == tracks && records.hasOwnProperty(tracks)){

id.push(tracks + []);
}
else{
return records;
}
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');

Oh I didn’t know that was what value meant? I was looking for a numerical value or something. That explains a lot that I was confused about.

I have this now. I am still not doing it right despite all the help. :confounded:

// Only change code below this line
function updateRecords(records, id, prop, value) {
if (id.prop != tracks && value != "") {
id.prop = value;
}
else if (id.prop == tracks && records.hasOwnProperty(tracks)){

id.push("tracks :" + []);
}
else{
return records;
}
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');

This challenge is always a challenge for those, who are starting out and are new to this. I was there once and have made it through. So, I hope you would too.
All the best.

2 Likes

You should start everything again from the beginning. Make sure each concept is understood, and you’ll be good.

I understand what you explained, which concepts do I need to understand?

(Not trying to be difficult or anything I honestly don’t know what concept/understanding I’ve been missing for the past 5 days.)

The dot notation still won’t work, lol

This is the key piece of syntax. The challenge is all about understanding this one piece of syntax. If you don’t know what it does, add a console.log to your function to see.

1 Like

Your understanding isn’t inadequate, just that this challenge requires you to construct logic in a way you’ve not been familiarized with in the previous lessons.