Profile Lookup - please help!

Hello everyone,

I will be very thankful if someone explained to me what I’m doing wrong here! I am struggling to find what’s wrong here :slight_smile:

Your code so far


function lookUpProfile(name, prop){
var i = 0;
for (i = 0; i < contacts.length; i++) {
if (name !== contacts[i].firstName) {
    return "No such contact";
} else if (!(contacts[i].hasOwnProperty(prop))) {
    return "No such property";
} else {
    return contacts[i].prop;
}
}

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

You are only ever checking the first value of the contacts array. Remember that a return statement ends function execution. Your code always returns when i is 0, so it never loops.