(need help with) Wherefore art thou

Hi everyone can someone plz explain to me why my code is not working am getting false when i should get true


function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line
for (let i in collection) {
  console.log(collection[i].hasOwnProperty(source))
}

// Only change code above this line
return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Wherefore art thou

Link to the challenge:

What are you returning? What logic do you have in there? In other words, what are you doing to get the right answer? All I see is that you are looping and logging out some data.

2 Likes

am just trying to see if source is inside collection so i can then push it to arr and return the answer

What type of thing is source? What types of arguments does hasOwnProperty use? Do those two types agree?

1 Like

ok if i understand hasOwnProperty correctly i should be able to compare 2 objects with it thats why am trying to loop inside collection and see if source is inside it (am i thinking correctly ?)

Parameters
prop
The String name or Symbol of the property to test.

i see that means i should transform source to a string and then compare it using Object.entries(source) thats correct ?

Not quite. The challenge wants you to check all objects in the array collection and find all that have every property of source and that property set to the same value.

2 Likes

ok perfect thank you so much :pray: :pray:

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