im more lost than a blind man in an empty room. I have tried everything i can think of and tried some of the other formats and codes ive seen on the forum. Im so confused with the whole object thing.
Your code so far
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'
}
};
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.tracks=value
} else if (prop=="tracks" && value!=="" && records.id.hasOwnProperty("tracks")==false) {
let newProp=[]
newProp.push(value)
}
return records
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build a Record Collection - Build a Record Collection
let’s look at some visual cues to help you out first.
When you look at your code, do you notice that one of the parameters is a different color than the rest?
to be honest, the video said that dot notation and bracket notation both represent/call a property of the object. I thought bracket notation was used more for properties with spaces or unformatted names. But I think it serves as a call to both the value in the function and the object property? as in it considers them as the same? like it assumes the id parameters is in the contextt of the id property in the given array? I honestly don’t know I’m very confused
by changing by "prop"s to brackets I got some tests to pass, I tried doing that with the “tracks” too, but that made them all fail again so I put it back to dot notation. this is what I have:
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].tracks=value
} else if (prop=="tracks" && value!=="" && records[id].hasOwnProperty("tracks")==false) {
let newProp=[]
newProp.push(value)
}
return records
}
console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"))
After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"), tracks should have the string Take a Chance on Me as the last and only element.
Failed:5. After updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"), tracks should have the string Addicted to Love as the last element.
Failed:6. After updateRecords(recordCollection, 2468, "tracks", "Free"), tracks should have the string 1999 as the first element.
ohhh i understand, so its used to represent a property without using its actual name so that u can use a different variable (such as prop) to represent that property within a function? also, where else should i look for these remaining tests?
How is that code UPDATING THE records OBJECT? Why would I be talking about the records object specifically? Do those two lines change the records object?
You are supposed to update the records. You do not use the variable records at all in those two lines, so you probably are not changing the records.
What change are you trying to make to the records with this part of the code? What should the final object look like after you correctly execute the requested logic?
how am i not using records? how do i call records? im trying to add a new property to an object in the records array. should i call the object by the id?
ahh I see. I had to use the id of the object to refer to the object in the array, and then add a prop. I don’t understand how that makes a new prop tho, wouldn’t that just be referencing an existing property such as artist?