Basic challenge JavaScript: Profile Lookup?

I have problems with this challenge. I know there is a solution already on this forum but I would like to know what am I doing wrong.

I am getting the following error:
TypeError: Cannot read property ‘Akira’ of undefined

Here is the challenge and my code so far

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes name and a property ( prop ) as arguments has been pre-written for you.

The function should check if name is an actual contact’s firstName and the given property ( prop ) is a property of that contact.

If both are true, then return the “value” of that property.

If name does not correspond to any contacts then return "No such contact" .

If prop does not correspond to any valid properties of a contact found to match name then return "No such property" .

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it 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.

Note: Backticks are not single quotes.


Thanks for your help and info @Sky020

there are a few issues with your code.
You use contact[i][name], but the name variable is not a property name, instead is the value of the firstName property

also, your loop is empty, the only thing it does is bring the i variable at value of contacts.length and contacts[contancts.length] is undefined, so you get the other errors that you can’t get a property of undefined

and other stuff, but actually using your loop is a good step toward a working solution

Thank you for your answer @ilenia
Some things are still hard to grasp. I have tried for few hours to understand the logic but I was missing some key things that I wouldn’t remember anyway so I checked for the solution on FFC page. Of course, it seems clear now.
I think that the idea or the logic from the challenge is still not planted in my head since I did not found the solution by myself.
In any case, I will try the challenge in a few days again to see if I can come to the solution by myself.
Once again thank you very much for your fast help and advice. It is encouraging to know that there is someone that can help me if I get stuck.

instead of looking, try asking again for help, if the first answer is not enough - it will give greater efforts for you

once or twice we could even work together on the same piece of code (using for example that have a multiplayer feature including an instant chat)

Next time I will for sure ask more than once, but sometimes it just seems that I have so much questions and I get confused and do not know how to formulate a question.

I mean if you have time I would like to go over the Record Collection challenge. This is also one challenge that I passed by looking at the solution and I think that I did not get the point. Or maybe you have something else in mind?

How can we connect on I have an account.


you can create a repl, there is a button to invite someone to partecipate, send me the link via PM here on the forum. Or it is possible to invite also via username - the link is a surer way I think - send me a PM to agree on a time