Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kumquatfelafel/e7574b2493b06bf1fad3d2c0abd6998c to your computer and use it in GitHub Desktop.
Save kumquatfelafel/e7574b2493b06bf1fad3d2c0abd6998c to your computer and use it in GitHub Desktop.

Gist for the FreeCodeCamp Profile Lookup Challenge. Instructions as comments. Total: 39 lines. We have an array of objects representing different people in our contacts lists.

Example: var contacts = [ { ... } , { ... } , { ... } , { ... } ];

// A lookUpProfile function that takes
// firstName and a property (prop)
// as parameters has been pre-written for you.
function lookUpProfile(firstName, prop){
   // The function should check if firstName is an actual contact's firstName
   // and the given property (prop) is a property key of that contact.

   // If both are true, then return the "value" of that property.

   // If prop does not correspond to any valid property keys
   // then return "No such property"


   // If firstName does not correspond to any contacts then return "No such contact"
   
}

Hints: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

There is a key word in the if firstName does not correspond to ANY contacts in the contact list.

And you need to look at the array of objects. And ask yourself how you're going to access data

from the objects inside the array elements.

And you need to look at the fact that the last six lesson were all about loops.

A few key previous lessons for solving this challenge:

Accessing Nested Objects

Accessing Nested Arrays

Accessing Objects Properties with the Dot Operator

Accessing Objects Properties with Bracket Notation

Accessing Objects Properties with Variables

Testing Objects for Properties

I'd also like to restate what was learned in "Return Early Pattern for Functions":

When a return statement is reached, the execution of the current function stops and control returns to the calling location.

If you're trying to run a loop and return, it will halt the function in turn halting the loop.

The last hint that I'd like to give is to think that you have a large stack of business cards, how would you psuedo-code accessing or returning information from the business cards?

How/when would you state that you don't have a business card for a person?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment