Tell us what’s happening:
Im wondering why my code is not getting through this problem, even when I tested the case by myself
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) {
switch(prop) {
case "artist":
if(value.length == 0) {
delete records[id][prop]
return;
}
records[id][prop] = value;
break;
case "tracks":
if(value.length == 0) {
delete records[id][prop]
return
}
if(records[id].hasOwnProperty(prop) && records[id][prop].length > 0) {
records[id][prop].push(value)
return;
} else {
records[id][prop] = [value]
}
break;
case "albumTitle":
if(prop == "albumTitle") {
records[id][prop] = value
}
break;
}
return records;
}
updateRecords(recordCollection, 2468, 'tracks', 'Free');
console.log(recordCollection)
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Record Collection
Link to the challenge: