question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi, I’m not sure this is a bug but I asked in help forum and was told that the code is right and it should work.

So this is my code:

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

The code works well with both “else if” statements, when either firstName or prop are false; but it doesn’t work when both are true. I even tried creating a new “else if” statement to cover the case where both conditions are false, but of course it doesn’t work either.

Thank you for your help.

Edit (by @raisedadead)

Challenge Name : Profile Lookup

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dcolonel6commented, Jul 8, 2016

mine doesnt even loop …after i have initialize person to 0 it doesnt increment accordingly

0reactions
shaheel-azharcommented, Jul 22, 2021

###This_Snippets_seems_great

// 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; x++){ if(contacts[x][“firstName”]==name){ if(contacts[x].hasOwnProperty(prop)===true){ return contacts[x][prop]; }

        else if(prop==contacts[x].hasOwnProperty(prop)===false){
            return "No such property";
        }
    }
}
return "No such contact";

// Only change code above this line } var a = lookUpProfile(“Harry”, “likes”); console.log(a)

Read more comments on GitHub >

github_iconTop Results From Across the Web

freeCodeCamp Challenge Guide: Profile Lookup
Profile Lookup · Hint 1. Use a for loop to cycle through the contacts list. · Hint 2. Use a nested if statement...
Read more >
CodeChallenge/Profile Lookup.md at master - GitHub
A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you. The function should check if firstName...
Read more >
trying to understand this profile lookup in JavaScript
I have used two different variables to track the missing conditions here. function lookUpProfile(name, prop){ // Only change code below this ...
Read more >
UserSearch: Find User Profiles | Dating Sites | Free Search
600+ sites Supported! Largest Reverse User Search Online! Find someone by username or email. Premium Reverse Lookup Tool FALL SALE : 75 ...
Read more >
JavaScript Algorithm: Profile Lookup | by Erica N - codeburst
We write a function that will look through an array of objects and return the value of a particular property if certain rules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found