Where is the 1 coming from?
Откуда взялся 1? this is selecting the album ID index of a specific album,
Что такое records[2468] ? this is the selection of a specific album by ID
You don’t need to use the 1. Where did the 1 come from?
By that specific id, yeah. How would you get at whatever album is corresponds to the argument id?
id[1] that’s what I think
I think that this example deserves to be divided into dozens of lines; it would be impossible to give more examples; it would be impossible to understand otherwise; why and how to compare there are a bunch of arguments, I don’t understand how it works.
There is no 1? Where are you getting the 1 from?
I’m honestly so confused. There is no 1. Only id
records[2468] gets the album with id number 2468. I’m asking how I would get at whatever album corresponds to the id number was passed into the argument for id.
why and how to compare there are a bunch of arguments,
I’m trying to get you to what the arguments do together.
Здесь нет 1? Откуда вы взяли 1? I select ID by index
by the index specified in the argument
There is no 1. Stop using 1.
Please show the syntax for using id to get an album from the records.
if we take the first condition if (value === “”) {
delete records[id][prop]; here the question has already arisen, if the values are empty, why delete delete records[id][prop] if the values are empty? There’s nothing there
Пожалуйста, покажите синтаксис использования id для получения альбома из записей.
Пожалуйста, покажите синтаксис использования id для получения альбома из записей.
records[id] As far as I understand it will show all entries with id
records[id] As far as I understand it will show all entries with id
There we go. This is an important first piece of knowledge.
- If
valueis an empty string, delete the givenpropproperty from the album.- If
propisn’ttracksandvalueisn’t an empty string, assign thevalueto that album’sprop.- If
propistracksandvalueisn’t an empty string, you need to update the album’stracksarray. First, if the album does not have atracksproperty, assign it an empty array. Then add thevalueas the last item in the album’stracksarray.
Everywhere it says here ‘the album’, it’s talking about records[id].
So for the first part I quoted, you need to delete the property from records[id]. So your code for this part must have records[id] and prop.
this i delete records[id][prop]
вам необходимо обновить
tracksмассив альбома. Во-первых, если у альбома нетtracksсвойства, присвойте ему пустой массив. Затем добавьтеvalueв качестве последнего элементаtracksмассива альбома.
вам необходимо обновить tracks массив альбома. Во-первых, если у альбома нет tracks свойства, присвойте ему пустой массив. Затем добавьте value в качестве последнего элемента tracks массива альбома.
here it also becomes unclear to me
What’s your current code?
Again, I can’t understand this code, it doesn’t fit in my head, it’s very complex, it’s easier to copy it than to rack my brain like that)))
I recommend against copying the answer.
Can you show me what your code looks like right now?
This sort of thing is exactly what’s hard about professional programming. The job is all about wracking your brain.
// 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;
This is looking pretty good.
// 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 !== "") {
// Update tracks property
}
return records;
}
Let me write the logic for updating the tracks property a little bit differently.
The tracks property is special because it’s an array that might already have other stuff in it.
-
make sure that if the tracks array doesn’t exist, you create it first as an empty array
-
add the new tracks
valueat the end of the tracks array
if(records[id] !== “tracks”){
records[id].push(“tracks”)
}
I see it like this
if(records[id] !== “tracks”){
records[id].push(“tracks”)
}
You mixed the two parts together. Let’s look at just the first part.
make sure that if the tracks array doesn’t exist, you create it first as an empty array
Can you do this?