My code returns correctly in vscode but I’m getting a reference error in the fCC console:
ReferenceError: assignment to undeclared variable property
I can’t spot the undeclared variable and would appreciate any help.
An explanation as to the discrepancy between the consoles and any tips to debug similar would be extra appreciated!
I’ve included an extra code block at the bottom that console logs the various fCC tests fro you convenience
**Your code so far**
function whatIsInAName(collection, source) {
const arr = [];
// Only change code below this line
collection.forEach(element => {
let allHere = true;
for(property in source){
if(source[property] != element[property])
allHere = false;
}
if(allHere)
arr.push(element);
});
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
**Optional consolelogging:**
let test1 = whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
let test2 = whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 });
let test3 = whatIsInAName([{ "apple": 1, "bat": 2 }, { "bat": 2 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "bat": 2 });
let test4 = whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }], { "apple": 1, "cookie": 2 });
let test5 = whatIsInAName([{ "apple": 1, "bat": 2 }, { "apple": 1 }, { "apple": 1, "bat": 2, "cookie": 2 }, { "bat":2 }], { "apple": 1, "bat": 2 });
let test6 = whatIsInAName([{"a": 1, "b": 2, "c": 3}], {"a": 1, "b": 9999, "c": 3});
console.log(`Test 1:`, test1);
console.log(`Test 2:`, test2);
console.log(`Test 3:`, test3);
console.log(`Test 4:`, test4);
console.log(`Test 5:`, test5);
console.log(`Test 6:`, test6);
Challenge: Wherefore art thou
Link to the challenge: