Hi,
I’m working on Basic JavaScript: Profile Lookup, and when I run the tests I got three that are failing, but when I call the function I get the expected values. What I am doing wrong?
Thanks!!
These are the tests that fail:
console.log(lookUpProfile(“Bob”, “number”));
console.log(lookUpProfile(“Bob”, “potato”));
console.log(lookUpProfile(“Akira”, “address”));
Here’s my code:
function lookUpProfile(name, prop){
// Only change code below this line
var contactExists = false;
for(var i=0; i<contacts.length; i++){
if(contacts[i].firstName === name && contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
if(contacts[i].firstName === name) contactExists = true;
}
}
if(contactExists) return "No such property.";
else return "No such contact.";
// Only change code above this line
}
console.log(lookUpProfile("Kristian", "lastName"));
console.log(lookUpProfile("Sherlock", "likes"));
console.log(lookUpProfile("Harry", "likes"));
console.log(lookUpProfile("Bob", "number"));
console.log(lookUpProfile("Bob", "potato"));
console.log(lookUpProfile("Akira", "address"));