Tell us what’s happening:
My issue is understanding this lines of code for question/guide/problem being asked to perform.
- If
prop
isn’ttracks
andvalue
isn’t an empty string, assign thevalue
to that album’sprop
.
code
// If prop
isn’t tracks
is asked why not prop !== for the else if statement below?
// since hasOwnProperty method will return boolean and === false to execute.
// what’s the purpose of saying if prop === tracks needs exist?
// back to “isn’t” makes me think to use !==
// Thank you for your help and the trouble im having explaining my problem
else if (prop === “tracks” && value !== “” && records[id].hasOwnProperty(“tracks”) === false)
{
records[id][prop] = [value];
}
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 (value == "")
{
delete records[id][prop];
}
else if (prop !== 'tracks' && value !== "")
{
records[id][prop] = value;
}
else if (prop == "tracks" && value !== "" && records[id].hasOwnProperty("tracks") === false)
{
records[id][prop] = [value];
}
else if (prop === "tracks" && value !== "")
{
records[id][prop].push(value);
}
return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15
Challenge: Basic JavaScript - Record Collection
Link to the challenge: