I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I don’t know, I’m learning. This was a suggestion on the hints also I saw someone else using it. That line of code seems to work. It is when tracks is set to that I can’t get it it to work.
your issue is that records[id].hasOwnProperty("prop") is always false
it is what I am trying to make you reflect on - what property are you actually testing? not what you want it to be testing, what it is actually doing. Read it carefully, what is it doing?
Tell us what’s happening:
Can you tell me why the code does not work. I’ve spent too much time on this and I can’t figure it out. I need direct instruction please.
This is the error message
// running tests After
updateRecords(recordCollection, 2468, “tracks”, “Free”)
tracks should have the string 1999
as the first element. // tests completed
Please help !
**Your code so far**
// Setup
var 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" && value === "" ){delete records[id][prop]}
else if (prop ==="tracks" && value === "" ){delete records[id][prop]}
else if ( prop === "tracks" && records[id][prop] !==[] && value !== "")
{records[id][prop]= [value];}
else if (prop === "tracks" && records[id][prop] ===[] && value !== "")
{records[id][prop].push(value);}
return records;
}
updateRecords(recordCollection, 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/92.0.4515.131 Safari/537.36 Edg/92.0.902.73
This seems like a logic error. You are basically deleting records[id][prop] whenever value === "" regardless of what the value of prop is. Was this your intention?
Thank you for formatting it for me. I’ll do better next time.
I have to deletes one for when prop is tracks and one for if prop is not tracks.
3.) I had hasOwnProperty(tracks) to check for but it still gave me one error message.
4.) So I really need a lifeline here. I have tried everything within my limited knowledge and either it says it cannot add the track to ABBA or 1999 is not the first track in 1999. I don’t get this because i push the value to the array it should remain first.
I tried ===[ ] out of desparation not logic
if the prop is tracks and the value is blank you delete tracks value
If the prop is album or artist and the value is blank you delete the album or artist
Isn’t that what is supposed to happen?