nateman
September 25, 2023, 1:00am
1
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) {
if (value === "") {
delete records[id][prop];
} else if (prop !== "tracks" && value !== "") {
records[id][prop] = value;
} else if (prop === "tracks" && 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/117.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Record Collection
Link to the challenge:
Learn to Code — For Free
This doesn’t seem like it should be empty.
nateman
September 25, 2023, 4:53pm
3
Tell us what’s happening:
Describe your issue in detail here.
I ended up figuring it out but I am lost on a few factors such as:
what does each one of these correlate to in the record collection (records, id, prop, value)
First, if the album does not have a tracks
property, assign it an empty array. Then add the value
as the last item in the album’s tracks
array.
(records[id].hasOwnProperty(“tracks”) === false) {
records[id][prop] = ;
}
does that mean prop and tracks are the same thing
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 !== "") {
if (records[id].hasOwnProperty("tracks") === false) {
records[id][prop] = [];
}
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/117.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Record Collection
Link to the challenge:
Learn to Code — For Free
Look at the else if
condition:
else if (prop === "tracks" && value !== "") {
So yes, in this instance, prop
is equal to “tracks”.
Did you see this part of the instructions?
The updateRecords
function takes 4 arguments represented by the following function parameters:
records
- an object containing several individual albums
id
- a number representing a specific album in the records
object
prop
- a string representing the name of the album’s property to update
value
- a string containing the information used to update the album’s property
You said they are with this if
condition
nateman
September 25, 2023, 5:16pm
6
(records[id].hasOwnProperty("tracks") === false) {
records[id][prop] = [];
}
records[id][prop].push(value);
so does this mean that it is searching the id for the property of tracks and if it doesn’t find it then it would create
tracks: then throw a value in the array at the end?
You wrote the code. What did you intend for it to do?
No, it is not searching id
for the “property of tracks”. The id
is a number. It is checking if the record object associated with the given id
has a "tracks"
property.