So, what am I missing here? There is an example that showed me how to update the collection, so I went ahead and did that. But nothing changes. Even the example properly updated ‘Abba’, but that particular requirement did not pass for some reason.
Challenge:
// 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) {
return records;
}
updateRecords(recordCollection, 5439, "artist", "ABBA");
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
updateRecords(recordCollection, 2468, "tracks", "Free");
updateRecords(recordCollection, 2548, "tracks", "");
updateRecords(recordCollection, 1245, "albumTitle", "Riptide");
It really helps if you post the link to the challenge.
I’ve edited your code 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.
The challenge is asking you to create a function that creates or update the record collection, in the code you shared above I can’t see the function you created.
This is not what you’ve been asked in this challenge, what you typed in here is just the different scenarios where the function you’ll write will do it’s job. Check the challenge requirements and try again.
Not much more than the Javascript taught so far in the course. In all fairness I was working on picking items from nested arrays which all sounded feasible and perfectly understandable and all of a sudden the next assignment turns to this. The example provided by the course creator with ‘abba’ being placed as artist so far made perfect sense but for some reason none of the requirements seem to ‘tick’.
Read this part carefully. Ask questions about the pieces that don’t make sense:
You start with an updateRecords function that takes an object literal, records, containing the musical album collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.
Your function must always return the entire record collection object.
If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.
If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
If value is an empty string, delete the given prop property from the album.
Records = record collection
id = the four digit number resembling the album
prop = property of the album such as albumTitle, artist and tracks
value = value of said property