Hello ! My can not pass challenge https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/
What is wrong with my code
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["JavaScript", "Gaming", "Foxes"]
}
];
function lookUpProfile(name, prop){
// Only change code below this line
var ar = "";
for (var i = 0; i< contacts.length ; i++) {
if (contacts[i]["firstName"] == name && contacts[i][prop] ) {
console.log(contacts[i][prop]);
ar = contacts[i][prop] ;
} else if (contacts[i]["firstName"] !== name ) {
ar = "No such contact" ;
console.log(ar);
} else {
ar = "No such property";
console.log(ar);
}
}
return ar ;
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "address");
"Kristian", "lastName"
should return "Vos"
"Sherlock", "likes"
should return ["Intriguing Cases", "Violin"]
"Harry","likes"
should return an array
Passed
"Bob", "number"
should return “No such contact”
Passed
"Bob", "potato"
should return “No such contact”
"Akira", "address"
should return “No such property”