Help! Basic JavaScript: Profile Lookup

I looked up the hints and they’re both not working so I’ve looked at what other users have entered and it’s still not passing all tests. I’ve got it to where "Bob", "number" returns “No such contact” and "Akira", "address" returns “No such property” but the rest of the tests fail.

What am I doing wrong?!

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 x = 0; x < contacts.length - 1; x++) {
    if (name == contacts[x].firstName && contacts[x].hasOwnProperty(prop)) {
        return contacts[x][prop];
    } else if (contacts[x].hasOwnProperty(prop) == false) {     
        return "No such property";
     return "No such contact";

// Only change code above this line
lookUpProfile("Akira", "likes");

Your browser information:

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

Challenge: Profile Lookup

Link to the challenge:

The above is the first problem.

The second problem is what if the firstName property of the first object does not match name and the first object does not have prop as a property? Your function will return “No such property” even if none of the other objects in the contacts array have a firstName property that matches name.

The third problem is, what if the firstName property of the the first object in the contacts array does not match name but has a property named prop but the last object’s firstName property does match name? Your function will never reach the last object, because you would have already returned “No such contact”?

1 Like

You know what? I thought the same thing but just needed confirmation from another set of eyes and it worked! Thank you so much!!!