User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.
Challenge: Record Collection
Link to the challenge:
How do function parameters determine the object properties.
usually the comma can separate properties and determine the function parameters.
Here in this object how does it work?
Why do you have a screenshot in your code? Is that purposeful?
To answer your question:
I think you are getting confused by the naming convention(if a case of 1 can be considered a convention) used in the above.
You decide to refer to a function argument with any name you want. This reference is called a function parameter.
So, this line has determined the function parameters:
updateRecords(5439, "artist", "ABBA");
The order is important:
function updateRecords(id, prop, value) {
// Inside the function:
id === 5439;
prop === 'artist';
value === 'ABBA';
}
Now, inside the function, you are able to do this:
Mutate the object by using the parameters(among other objects). This is never recommended.
Have your function return a new object that is based on the original collection object, but has a few properties changed.
Example:
//create a copy of the original object
function update(value) {
let myObj = { ...collection };
// Change some values
myObj[2548].album = value;
return myObj
}
// call the function
var updatedObj = update("New Album");
// this is the first object of collection object
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
}
}
And in this function
function updateRecords(id, prop, value) {
if(value === "") delete collection[id][prop];
how it determine ,
id ===2548;
prop === 'artist or album';
value === 'track';
simply which comma in the object separate them ,like that order?
The order you pass arguments to a function, is the order they will be assigned to the parameters.
example(1, 2, 3);
function example(a, b, c) {
a === 1; b === 2; c === 3;
}
//--------------------------
example(2, 3, 1);
function example(a, b, c) {
a === 2; b === 3; c === 1;
}
If you are not understanding this line:
if (value === "") delete collection[id][prop];
Then:
The if statement checks to see whether the valueparameter has been passed as an empty string.
If the if is true, the property prop of the property id is deleted from the collection object.