JavaScript Object

Hi, I am new here and I need your help In this code/challenge first they create an Object and they associate with Function and I want to know how this code works…

Hello,

Welcome to the forums!

The code in the challenge isn’t finished, so it doesn’t work to start.

And you have not posted any of your code here, so I am not sure what you want to know, what you have tried, or where you are having difficulty about how it works.

All of the previous challenges in the section of the course are building up to this challenge.

You are supposed to make the function update property names and values in the object, by checking that certain properties exist and if they dont, create them or delete them according to the challenge requirements specification.

You need to use everything you’ve learned up to now to accomplish this task.

Unless you have a specific difficulty performing any of the tasks, I don’t know how to help you.

If you are lacking understanding of any of the concepts necessary to perform this task, I’d suggest you go back and review previous lessons or look them up.

If you got here and don’t have any idea of where to begin, I think you are going through the challenges too fast. Slow down and focus on the concepts.

I can’t just give you the solution, because, how would you learn by just getting the answer?

yes, thank you so much…

I just want t know that how Function parameters have relation with Object properties?
like:
"function updateRecords(records, id, prop, value) "
"records, id, prop, value "
how these are connected with object properties without ant declaration…?
I am confused…

The arguments are like placeholders, variables, for parameters that will be passed to the function when it is called.

recordsCollection is the object

id is the record id (the number in the object)

prop is the property names such as artist and tracks

value is the property values of prop such as Prince (value of artist) and '1999', 'Little Red Corvette' (value of tracks)

So you need to use that information along with methods and concepts you have learned up to now to update the Object according to the challenge requirements

You will need if conditional statement, push(), hasOwnProperty, bracket notation

1 Like

The function doesn’t really care about the specifics, you tell it those inside the function body. The operations you do inside the function.

Based on what method you use with what variable, it will return the correct output, or return a type error if you try to perform an operation on a string with a method that can only be used on an array. Or return incorrect values if you do the wrong operations.

That is what is known as the function definition and your task is to define that function so that the output works and makes sense for the data you pass to it, and that the return values satisfy the requirements. of the challenge.

ok, that’s why we don’t need any declaration

Correct. In the challenge, they already began the declaration for you with this:

// Only change code below this line
function updateRecords(records, id, prop, value)  <-- function
                                                      definition

{                   <-- start of function body
  return records;   <--- function body
}                   <--- end of function body

You just need to fill it in and make it work. :slightly_smiling_face:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.