Profile Lookup - please help!

Profile Lookup - please help!
0.0 0

#1

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/


#2

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.


#3

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.