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');
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');
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.
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.
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.
Okay I’ll change it back. The only reason I keep changing the notation is because I’m still getting X’s for every single lesson objective so assumed I still must be getting the notation wrong.
Wherever I put it that doesn’t just cause a syntax error with the red wriggly lines I get.
‘ReferenceError: Can’t find variable: tracks’
Meaning the tracks variable doesn’t exist. Which I don’t understand because it must exist. It’s up there in the recordsCollection code and is assigned strings. Is my code making tracks stop existing somehow?
(id) this stands for the identifier. It could be anything but they are numbers, here. You can access using bracket notations. Like this: records[id]
which is the same as writing recordCollection[5140]
It will display the targeted id but since we ain’t targeting only one id, it’d be better to use the initial method of accessing it.
(prop) these are the properties in the id:
such as tracks, albums, e.t.c. it can be accessed using dot notation or bracket notation.
Okay. So I think I was mixed up because track is a property after checking previous lessons.
So okay those are variables and those are properties. But how do I access tracks without confusing the code into thinking I’m after a variable called tracks?
Here’s my code.
// Only change code below this line
function updateRecords(records, id, prop, value) {
if (records[id][prop] != tracks && value != "") {
records[id][prop] = value;
}
else if (records[id][prop] == tracks && records[id][prop].hasOwnProperty(tracks)){
records[id][prop].push(tracks + []);
}
else{
return records;
console.log;
}
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
I hope this makes sense but this is my understanding
Records → id → prop
I understand it like a computer directory in my head. I’m using this directory (the bracket notation) to access the properties I need to access.
This is how I understand Javascript objects also, as a file structure. I know they’re not exactly like that, but it’s how I get my head around them and the idea of accessing data in them.