Tell us what’s happening:
Describe your issue in detail here.
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) {
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/106.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Record Collection
Link to the challenge:
Okay seriously. Where to even start on this one? Things sure got hot fast.
I have no other way to even begin to solve this other than looking at the solution and trying to deduce the steps involved. Any one actually get this without looking at the solution?
{
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'
}
}
This is an example of what the records input will look like. If I tell you to change record 1245 so that its "artist" is "Some Band", then I’d expect the output to look like this:
{
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: 'Some Band', // this value got updated
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
}
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’
}
};
Now it calls this function
function updateRecords(records, id, prop, value)
Lets look at that 4 function arg updateRecords
First of all updateRecords is never actually invoked but its elements are
According to the solution
1.records
2.id
3.prop
4.value
these are all constantly referred to in the output
Take for example the value 2548
As far i understand this is stored here
updateRecords[0]
Therefore
updateRecords[1]
must be album title
I hope i am right so far. The guides only touched up on this so far and perhaps i have sped through too fast. Anyhow.
Lets take updateRecords[1][1]
That must be
Slippery When Wet
1999
Am i right?
Lets go back to the 4 args
They are string literals.
So why do they represent? What does id currently point to ?
What does prop currently point to?
What does records[id] point to?
What does records[id][prop]
I can only assume to guess at this point hoping that my previous assumptions were correct before.
Okay i think i have hit some level of understanding.
Id is the 4 digit code number before the prop information stored in the brackets. Value is kind of like the user input when entering in new information.
So when some of object is passed to the function (user input) it gets checked into the system somehow under such conditions as
If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.
Lets take for example a string is passed to the system of 5439, “artist”, “ABBA”
First the system checks if value !== “”
So easy. Checks if an actual value is passed in with some letters
Next it is checking if 5439, “artist”, “ABBA” by
if (prop !== ‘tracks’
Then update
records[id][prop]= value;
In literal translation what exactly is happening here with the string 5439, “artist”, “ABBA”
Something happens with the value of 5439 and the string prop of “artist” and “abba”
I will continue to look into this tomorrow. I work full time lol. Blue collar life.