Profile lookup exercise - why is my answer not accepted

Profile lookup exercise - why is my answer not accepted
0.0 0


Hi all, this exercise is driving me crazy. Here’s the link to the challenge:

And here’s my solution:

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
// Only change code below this line
    for (var i = 0; i < contacts.length; i++) {
    if(contacts[i].firstName == name) {
        foundName +=1;
    if(contacts[i].firstName == name && contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
    } else if(contacts[i].firstName == name && contacts[i].hasOwnProperty(prop)==false) {
        return "No such property";
    }   if (foundName < 1) {
        return "No such contact"};

var foundName = 0;

// Only change code above this line

// Change these values to test your function
lookUpProfile("Sherlock", "likes");

It’s ticking all of the requirements except 2. It says:

“Bob”, “number” should return “No such contact”
“Bob”, “potato” should return “No such contact”

But I’ve run this a million times in my web browser, storing the result of the function to a variable, and when I access the variable using the above criteria (i.e. “Bob”,"number’ etc) I do get “No such contact”. I can’t work out why this won’t be accepted.


Try to move foundName at the start of the function ( before the for...loop ): when i copy-pasted your solution that was out of the function^^