Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup- help needed please

Tell us what’s happening:
So this is my code so far, but I cant seem to get it to work with the other required properties and values.
I thought I could just add another 'lookUpProfile ’ call, but it didnt make a difference.
I am looking for any help to this issue.
Many thanks

Your code so far


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

// Only change code above this line
}

lookUpProfile("Bob", "number");


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Profile Lookup

Link to the challenge:

you need to return strings exactly as required
the strings in your code do not match the required strings
case for example is important

Thanks for that but there are more than one required strings.
not sure how to do that.
many thanks

the challenge instructions say:

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" .

look at your code, the strings are different:

return contacts[i][prop] || "no such property";

return "no such contact";

1 Like

I think my problem here is that I dont quite understand the code…

You have "no such contact", it should be "No such contact"
you have lower case "n", it should be upper case "N"

1 Like