where did I go wrong please help me…Thank you
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
var collectionKeys = [];
for ( var i = 0; i < collection.length; i++){
collectionKeys.push(Object.keys(collection[i]));
}
var sourceKeys = Object.keys(source);
//for every key pair
for ( var t = 0; t < collectionKeys.length; t++){
console.log(collectionKeys[t]);
//for every key in key pair
for ( var x = 0; x < collectionKeys.length; x++){
console.log(collectionKeys[t][x]);
//see if key matches
for ( var y = 0; y < sourceKeys.length; y++){
if( sourceKeys[y] == collectionKeys[t][x]){
if( collection[t][collectionKeys[t][x]] == source[sourceKeys[y]]){
arr.push(collection[t].first+ " " + collection[t].last);
}else{
console.log("value not found");
}
}else{
console.log("key not found");
}
}
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });