nehlzin
November 30, 2021, 10:41am
1
am stuck guys, HELP!
**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(prop !== "tracks" && value !== ""){
records [id][prop] = value;
}
else if(prop === "tracks" && records[id].hasOwnProperty["tracks"]){
records [id][prop] = [value];
}
else if(prop === "tracks" && value !== ""){
records[id][prop].push(value);
}
else if(valu ===""){
delete records[id][prop];
}
return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
Challenge: Record Collection
Link to the challenge:
Jagaya
November 30, 2021, 11:02am
2
The error you get is quite clear: you cannot “push” into an empty object.
You first need to CREATE the array, then you can push.
1 Like
How do we execute a function, like hasOwnProperty
?
1 Like
records[id].hasOwnProperty[“tracks”] → The .hasOwnProperty will give u a boolean result “True” or “False”, I think you should specify what answer from it you want in order to excecute the code, talking about the second condition (first Else If), and if the aswer is false then you should create the Tracks array and add value to it, then, u add the -e that u miss at the last condition and you should be done
1 Like
nehlzin
November 30, 2021, 11:40am
5
thank you @Jagaya
i added this statement:
else if (prop === “tracks” && records[id].hasOwnProperty(“tracks”) === false) {
records[id][prop] = [value];
nehlzin
November 30, 2021, 11:44am
6
thank you @Sebas_16
challenge SOLVED.
noticed I didn’t specify at first , so I did this instead:
else if (prop === “tracks” && records[id].hasOwnProperty(“tracks”) === false) {
records[id][prop] = [value];
1 Like
Kay21
November 30, 2021, 12:43pm
7
No I can’t solved this problem.
Hi @Kay21 !
Welcome to the forum!
If you need help with record collection, then please create your own post and people will assist you there.
Thanks!
system
Closed
June 1, 2022, 3:24am
9
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.