Before you start to read my question please understand I am a very confused beginner.
I can’t even seem to get this one off the ground and I’ve been working on it on and off for days. I am really trying super hard to not give up and look at the answer!
Starting with the very basics…
I see that we are supposed to write a code that uses ‘id’ , ‘prop’ and ‘value’ as variables.
From the challenge: Write a function which takes an album’s id
(like 2548
), a property prop
(like "artist"
or "tracks"
), and a value
(like "Addicted to Love"
) to modify the data in this collection.
Correct me if I’m wrong:
The ‘id’ is the four digit number that represents the record in the collection…Got it.
I understand the ‘prop’ variable to be the properties of the objects, the bits that sit on the left side of the semicolon in the contents of objects. I understand the ‘value’ variable to be the values that the individual properties are referring to, the bits on the right side of the semicolon.
ex. var Object = {
“property1” : “value1”,
"property2 ": “value2”
}
Now my question is how does the code know that when i use the variable ‘id’ I am referring to the four digit code for each album? Do I have to write code that explicitly tells the computer that ‘id’ is equal to each object in var collection? Or is this some type of hard wired code in Javascript and everytime I use the variable ‘Id’ in a function where I am manipulating Objects it already knows that ‘Id’ is the variable that refers to the name of the Objects.
I am assuming before I write any if/else if statements I need to let the code know what I am talking about when I use ‘Id’, ‘prop’, and ‘value’, in any subsequent code.
I understand that: collection[0] = “2548” , collection[1] = “2468”, collection[2] = “1245”, collection[3] = “5439”…
But how do I write code that sets ‘id’ equal to the objects in collection?
I am thinking something like this:
var x = 0;
var id = collection[x];
(code that tests the individual album according to the problem)
x ++; (increment to next object)
I realize this code above really doesn’t make sense and would require some type of loop but we haven’t been taught loops up to this point. You see what I am trying to do I’m sure… test the first album, then the next, then the next in succession.
Am I even in the ball park here?
Super confused guys…