I could do with a piece of advice on "Profile Lookup"

Hi guys! I’m very thankful for all the hard work and energy that you (FCC-guys) put into this site.
I seem to got stuck at this challenge. I’ve read all I could. I’ve looked through my code from line to line several times to check if I messed something up with the ‘(’-s, ‘)’-s, ‘{’-s or ‘}’-s. Finally I copy-pasted my code to jsbin.com to doublecheck if it works. And it works there, giving all the desired results, yet on the FCC-site it gives me an ‘X’ to all the specified test-cases. I don’t get it. Could you tell me what I should change and why? Thanx in advance!
So here’s my function:

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

Hey @martha_01!

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.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

I have added the challenge link to your post so other campers can see what challenge you are working on.

You are almost there just a couple of things.

In your current code you are not actually returning anything. It is great to use console.log to check out what is happening in your code but you do have to return your results in the function.

Also you will need to remove the periods here.

I hope that helps!

1 Like

Hi @martha_01,
console.log ( ) is not returning values from the function. So the returning value must use with return keyword like this.

return contacts[i][prop];

also, you can directly use strings with return keyword.

return "No such property";

Use exactly the same string message for No such property and No such contact . there is no full stop at the end.

I think these changes will work on your code. :slightly_smiling_face:

1 Like

Thank you!
Thank you!
Thank you!
Your remarks were super helpful!
I made the changes you suggested and and now my code works indeed.
Have a blessed day!

1 Like

Thank you for your answer!
I changed what you mentioned and now my code works properly.
A big THANK YOU! to you! :smiley:

1 Like