Hello all, this is my first time posting in the forum.
I have been struggling with that challenge for about a week now.
I almost passed all the conditions, but I can’t seem to get the " After updateRecords(recordCollection, 2468, "tracks", "Free"), tracks should have the string 1999 as the first element." right.
I would be glad if anyone had an idea of what is wrong with my code.
Please and thank you!
P.S: English is not my native language, kindly excuse the mistakes that might be in my speech.
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 (value == "") {
delete records[id][prop];
} else if (prop != 'tracks' && value != "") {
records[id][prop] = value;
} else if (prop == 'tracks' && value != "") {
if (records.hasOwnProperty([id][prop]) === false) {
records[id][prop] = [];
records[id][prop].push(value);
}
}
return records;
}
console.log(updateRecords(recordCollection, 2468, "tracks", "Free"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
I do not want to ignore it.
Isn’t the " if (records.hasOwnProperty([id][prop]) === false) " supposed to work only if the tracks array doesn’t exist and if it exists already then just push the value at the end?
I don’t get why the value is being pushed but the already existing tracks are being deleted.
Why would the entire ‘records’ object have a tracks property though? The entire records object consists of individual records. The individual records themselves have properties like tracks and name.
Oh my, I finally figured it out. [prop] doesn’t exist in the original object, so I can’t search for it.
Thank you so much for your help. Just knowing where I should search for an error was really helpful.
Now I can move on!