Hi
Having some issues here so hoping someone can shed some light on this for me.
In the part of code : if (prop !== ‘tracks’ && value !== “”),
If I use the (===) here instead of (==) I get a syntax error.
Its fine for the other parts of code but not when I negate the a boolean value (!==), it does not work.
In the piece of code above, I was under the impression that the properties of an object could be written as a string or other as it would be converted to a string and it seemed so in other tasks however, it returns a syntax error here without quotes.
What am I missing here?
I cant use dot notation in this code, anywhere I substitute it I get an error.
And why cant I use undefined instead of empty quotes? Why would there be a set of quotes with nothing for a value as an input where as undefined would work with no input?
Any help is much appreciated. I found this quite hard. I think I need to spend more time to thoroughly understand the material before I move onto another task.
So thanks ahead.
**Your code so far**
// 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: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(object, id, prop, value) {
if (prop !== 'tracks' && value !== "") {
object[id][prop] = value;
} else if (prop === "tracks" && !object[id].hasOwnProperty("tracks")) {
object[id][prop] = [value];
} else if (prop === "tracks" && value !== "") {
object[id][prop].push(value);
} else if (value === "") {
delete object[id][prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36 Edg/88.0.705.74
.
Challenge: Record Collection
Link to the challenge: