Syntax issue with the Record Collection Exercise in JS

Hello,

I think I have the bones of a solution to this exercise ( Record Collection) , but I’m getting tripped up on syntax. Can someone tell me what I am missing here:

function updateRecords(records, id, prop, value) {
if (prop != 'tracks' && value.hasOwnProperty = true) {
prop = value;

I get this error:

SyntaxError: unknown: Invalid left-hand side in assignment expression. (24:4)

  22 | // Only change code below this line
  23 | function updateRecords(records, id, prop, value) {
> 24 | if (prop != 'tracks' && value.hasOwnProperty = true) {
     |     ^

Am I using the operator incorrectly? Or is this some sort of dumb syntax thing I am just plain missing?

Thank you!

you want to use the equality operator here (===), not an assignment. And value.hasOwnProperty is not a correct piece of code.

And if some expression returns a boolean value, then comparing the returned value with boolean is redundant.
if (obj.hasOwnProperty("somePropName")) // correct
if (obj.hasOwnProperty("somePropName") === true) // correct, but redundant

1 Like

.hasOwnProperty is to be applied on object type so to check whether the object records has a property has the value of variable prop or not it should be done like records.hasOwnProperty(prop)==true
but as you have to check for the prop inside objects nested in records object you’ll have to use bracket notation to access the id and then check for property.
My explanation might be weird bcz i learnt js recently and solved this question today only.

Thanks for the help! I am past that issue and a couple others :slight_smile: Not quite there but moving along.

Nice!
I’m stuck on profile lookup question for soooo long now

Are these instructions preparatory for the kinds of direction one gets as a professional developer?

Understanding and modifying complex data structures is a pretty key skill in being a professional developer.

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