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.

Profile Lookup Challenge, Done everything but only passing 2/5

See original GitHub issue

The problem is that the first if condition has a problem that I think is trivial but I can’t figure it out ath the same time … Challenge Profile Lookup has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


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

// Change these values to test your function
lookUpProfile("Harry", "likes");

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
pitlv2109commented, Jun 14, 2016

I think this challenge is designedly bad. The three incorrect answers from your code were the ones that had property with value(s), weren’t they? For example, lookUpProfile(“Sherlock”, “likes”);. Well, when the for-loop runs, it will not iterate from 0 to contacts.length - 1. The value of i will only be 0. Do you see why? After the first run, there will be a return statement no matter what. Therefore, the for-loop (and the function) will end.

No matter how designedly bad the challenge is, there are solutions. Here is mine if you want to take a look at it

function lookUpProfile(firstName, prop) { // Only change code below this line for (var i = 0; i < firstName.length; i++) { if (contacts[i].firstName === firstName) { if (contacts[i].hasOwnProperty(prop)) return contacts[i][prop]; return “No such property”; } } return “No such contact”; // Only change code above this line }

P.s: If you have coded in complied programming languages, such as C, C++, Java, etc. (I’m not sure if this is JavaScript or the compile that FreeCodeCamp is using), when you use if-else statement, there will/must always be an “else” at the end of this if-else statement (you has else if).

2reactions
brainExplorercommented, Jun 18, 2018

solution: function lookUpProfile(name, prop) { // Only change code below this line for (var p in contacts) { if (contacts[p].firstName === name) { if (!contacts[p].hasOwnProperty(prop)) { return ‘No such property’; } return contacts[p][prop]; } } return “No such contact”; // Only change code above this line }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Profile Lookup Challenge, Done everything but only passing 2/5
Challenge Profile Lookup has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.
Read more >
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 >
Profile Lookup freeCodeCamp Challenge JavaScript - YouTube
In this video, I demonstrate and explain how to solve the ' Profile Lookup ' basic JavaScript challenge from www.freecodecamp.org.
Read more >
Profile Lookup, freeCodeCamp Basic Javascript - YouTube
Show your Support, Buy a Sticker! https://believerationally.com/shopIn this challenge, we learn how to look through an array of contacts in ...
Read more >
Profile Lookup - Free Code Camp - YouTube
In this tutorial called Profile Lookup, we iterate through an array of objects and test those objects to see if they fit specific...
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