Ask coding questions

← Back to all posts
Can anyone help me with the freeCodeCamp task?
michaelodumusi (0)

// 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: {
albumTitle: 'Clues',
artist: 'Robert Palmer',
tracks: ['Johnny and Mary']
},
5439: {
albumTitle: 'ABBA Gold',
artist: 'ABBA',
tracks: ['Take a Chance on Me']
},
};
// Only change code below this line
function updateRecords(object, id, prop, value) {
if(prop !== 'tracks' && value) {
object[id] = value;
} else if(prop === 'tracks' && !object[id].hasOwnProperty('tracks')) {
object[id] = value;
} else if (prop === 'tracks' && value) {
object[id].push(value);
} else if (!value) {
delete object[id];
}

return object;
}

updateRecords(collection, 5439, "artist", "ABBA")
updateRecords(collection, 5439, "tracks", "Take a Chance on Me")

I'm getting the error message "After updateRecords(collection, 5439, "tracks", "Take a Chance on Me"), tracks should have the string Take a Chance on Me as the last element."

Comments
hotnewtop
xxpertHacker (865)

If you can't complete an FCC challenge, you can just click the button that shows an answer.

DynamicSquid (4629)

Could you link the repl?

michaelodumusi (0)

@DynamicSquid Making one now, kinda new to this