I’m really struggling to know where to even begin with this one.
I know I have to return all the data about a given record but I don’t know how to do this. I’ve checked the forums but the code I’ve seen there doesn’t make sense to me. I know it should at this point but I just can’t get my head around it.
Can someone please help and explain where I need to start with this? I’ve got some code but I am so confused where to go from here.
**Your code 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 (records.hasOwnProperty(id,prop,value)){
return records;
}
else {
return "";
}
}
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0
Both are objects. That’s what is tricky here. You have a record collection object that holds many record objects. (This is one of the ‘big step forward’ challenges)
It might help to see what the parameters are doing by using some console.logs
Run this code here to see what records returns
// Only change code below this line
function updateRecords(records, id, prop, value) {
console.log(records)
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
Then run this code to see what one of the objects returns.
Hint: I am using bracket notation which is helpful to you.
// Only change code below this line
function updateRecords(records, id, prop, value) {
console.log(records[2548])
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
Wait ignore that, I got it!
Now I’ve just got to do all the other code requirements.
// Only change code below this line
function updateRecords(records, id, prop, value) {
if (prop != "tracks" && value != "") {
recordCollection[id].tracks = value;
}
return records;
}
Edit: put under spoilers. Sorry was just excited to have worked it out.
Because if I don’t use a bracket notation for id I get an error. I’ve looked at the lessons again and I’m still confused about when I should use it VS dot notation.
Is this right?
// Only change code below this line
function updateRecords(records, id, prop, value) {
if (prop != "tracks" && value != "") {
recordCollection[id][prop] = value;
}
else{
return records;
}
}