Tell us what’s happening:
What’s wrong? I followed the video tutorial to the letter. Does it have something to do with the quote marks being different? I tried to account for that.
Your code so far
// Setup
var collection = {
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(id, prop, value) {
if (value === ''){
delete collection[id][prop];
} else if (prop === 'tracks') {
collection[id][prop] = collection[id][prop] || [];
collection[id][prop].push(value);
} else {
collection[id][prop] = value;
}
return collection;
}
//Alter values below to test your code
console.log(updateRecords(5439, 'artist', 'ABBA')
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.
The solution still works, it’s just that the lesson was updated but the video hasn’t. You will need to copy your solution and reset the code, updating the solution accordingly.
The new test requires you to update the passed object instead of the collection that’s initially setup (this one is just for reference):
// Setup
var collection = {
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(object, id, prop, value) {
// paste your solution here and replace collection with object
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
Hi, first of.
I just started learning and I have no idea how comment works in fCC
getting to your problem, I believe @skaparate 's instruction is correct. To add on, your function updateRecords(id, prop, value) should be function updateRecords(object, id, prop, value)
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Do I have to make an entry for each element of the collection?
No, you have to test if the property exists, otherwise create it so you can handle errors . In this case, test that the array exists, otherwise initialize it.