Tell us what’s happening:
Describe your issue in detail here.
so to solve the problem, we have to basically use conditional.
according the second , we have to write:
if(prop != tracks…); but here prop is a property.
as i have learned in the previous lesson to access the property i need to use dot and bracket notation. but in this case i have accessed only by calling it’s name(prop). Why is that?
**Your code so far**
// Setup
var 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/90.0.4430.93 Safari/537.36.
prop is a string, which also happen to be one of the property names of an object
but first of all it’s a variable holding a string, as such you can check the value of the variable with !=
If you want to get the value of the property with that name, then you need to use dot/bracket notation
it is holding a string? i didn’t get this one
2.“If you want to get the value of the property with that name, then you need to use dot/bracket notation”…could you explain this simply or with an example it will be very helpful. thank you
but that is just the value of the variable
we know it’s also a property name, and if we want to get the value of the property we need to use bracket notation (you can’t use dot notation with variables)
but i didn’t declare prop as a variable here? neither did i assign it to a name in object .so why can i still compare it as a string holder or a string itself?
prop was not mentioned in the object also …so is it that automatically objects property are denoted as prop?
how can records be a object literal, there is dissimilarities in it’s syntax.
for ex; it should be- records={ } @ieahleen
The function arguments are defined outside of your function and passed in. You don’t declare or define the values of the arguments inside of your function. That defeats the purpose of reusable functions.
records is always an object, like the sample recordCollection
id is always a record id
prop is always a string of a property name
value is always a value to set or an empty string to indicate deletion
so if i write the arguments in this order
then first one will be object, second one will be id , third one will be prop , fourth will be value ? or such that,
it depends on the keyword itself( for ex: id for indicating id)?
If id is a record id
prop is a string of property name mentioned in the records object
value is the value of the object records
Why is it comparing with the datas inside the record collection object?
function parameters can be named in any way you want, but the description tells you that the function will be called with 4 arguments, of which
the first one is an object, the object that has to be updated,
the second one a number, a property of the object passed as first argument,
the third a string, which is a property of the inner object
the fourth is a string too, and it is the value to use to update the property with the name equal to the third parameter, or an empty string, and then the property is to remove
they could be named in any way, in this case the prewritten parameters are records, id, prop, value
but you could also totally write
function updateRecords(potato, orange, maple, ruby) {
}
and potato is the passed in object, orange is the id, maple is the property name and ruby the value to use to update the maple property
like any variable, function parameter names are totally arbitrary
here the recordCollection object is passed in as first argument and it will be referenced with records or potato in the function, 5439 is passed in as second and it will be referenced as id (or orange, 'artist' is passed in as third argument, and it will be referenced as prop (or maple), and 'ABBA' is the fourth argument and it will be referenced as value or ruby
each time the function is called with different values, those values will be referenced inside the function using the parameters
so it mainly depends on the argument i give,
updateRecords(records, …)
so if i had called updateRecords(5439, …);
then records would have been a id instead of an object?
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.
can you tell why my above code is not fulfiling the following task?
a few issues, yes hasOwnProperty is an object method, you need to use it on an object, not an undefined value
you are also overwriting the function parameter value
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.