Plz help! Can't figure out what is wrong with code! :-(

Does anyone see anything wrong with this code? Any help is appreciated!

function whatIsInAName(collection, source) {

  var srcKeys = Object.keys(source);

  return collection.filter(function) {
    for (var i = 0; i < srcKeys.length; i++) {
      if (
        !obj.hasOwnProperty(srcKeys[i]) ||
        obj[srcKeys[i]] !== source[srcKeys[i]]
      ) {
        return false;
      }
    }
    return true;
  });
}

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

Learn Intermediate Algorithm Scripting: Wherefore art thou | freeCodeCamp.org

What problems are you having? Can you narrow down what you think is wrong with it?

Everytime I try running the tests, it says “SyntaxError: unknown: Unexpected token”. Does that mean I wrote something wrong or does it mean something else?

“Unexpected token” almost always means that you have a mismatch of opening and closing symbols like braces ({}), parenthesis, (()), brackets ([]), etc. Check your braces and parentheses carefully and make sure that you have the right number of each and that the closing symbols are in the correct place.

2 Likes

The error message is pointing to this part here

once you clean that up then you should be getting a different error message concerning this part here

It doesn’t look like you defined obj anywhere.

2 Likes

Oh crap!:joy: I can’t believe I didn’t even see that! It passed the test! Thank you so much, @jwilkins.oboe! Thank you for your help as well, @ArielLeslie.

Congratulations on working through the problem! Happy coding.

This was incredibly helpful. Thanks!

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