Intermediate Algorithm Scripting: Wherefore art tho

Tell us what’s happening:
In the for loop, I am looping through all the second properties in the first argument, if it is equal to the property of the second property, I am pushing that object to an array and returning that array.

But I have written the second property name, which could change once we call the function with various property names, which is precisely what is happening.

Can someone help me as in how I can fix this issue?


Your code so far

function whatIsInAName(collection, source) {
let firstArgument= [...arguments[0]]
let secondArgument= arguments[1]
for (const key in secondArgument) {
  //This will give key
    let argSecond= key;

var arr = [];
for (let i=0;i<firstArgument.length; i++)
   if (firstArgument[i].last===secondArgument.last){

// Only change code below this line

// 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/86.0.4240.75 Safari/537.36.

Challenge: Wherefore art thou

Link to the challenge:

If you know the name of an object’s property, you can access that property with dot notation:

If you don’t know the name yet, but you know you’ll get it stored in a variable, you can access that property with bracket notation: object[variable].

1 Like