Hello All, I need help with this exercise. There are a few parts to this exercise but I guess what’s tripping me up first is how do I access a key that is a number when I thought we could not have keys as numbers, because JavaScript automatically turns those numbers into strings. so first this exercise I know I am suppose to update the record collection however I’m a bit loss and don’t know where to start on this exercise.
I only wrote one line of code for this exercise and I know I’m not even close But I figure why not give what I came up with so far. I m new to the hasOwnProperty method and I forgot I needed a conditional statement and Im pretty sure i need to use that method for this question.
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", //album and name of tracks missing
tracks: [],
},
5439: {
albumTitle: "ABBA Gold", //artist and tracks missing
},
};
// Only change code below this line
function updateRecords(records, id, prop, value) {
var records = recordCollection[id].prop.value; // <-----my one bad line of code
return records;
}
// 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) {
var records = recordCollection[id]['prop']['value']; //<----- I also tried this way
return records;
}
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/90.0.4430.212 Safari/537.36
Challenge: Record Collection
Link to the challenge: