Profile Lookup can it be done using only the knowledge from previous tasks

Tell us what’s happening:

I don’t know what to do without looking at hints and solution. And I don’t want to use hints and solution. I want to complete this task on my own. The question is if amount of knowledge from previous tasks enough to complete this task without using external sources and hints, because when I’m brushing through previous task over and over nothing helpful comes to my head that my help me in finishing current one.

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
    

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");


/* BACKUP COPY */

/*
function lookUpProfile(name, prop){
// Only change code below this line
    var data;
    for (var i = 0; i < contacts.lenght; i++) {
        for (var j = 0; j < contacts[i].length; j++) {
            if (name === "firstName" && prop === prop) {
                data = prop;
                return data;
            } else if (name !== "firstName") {
                data = "No such contact";
                return data;
            } else {
                data = "No such property";
                return data;
            }

        }
    }
    return data;

// Only change code above this line
}

*/

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/

Yes. At this point in the curriculum, you have everything you should need to complete this challenge. The only potential gotcha is checking if the object contains the given property, but that was covered in this earlier lesson.

now, looking at the code you’ve commented out, it seems to me it isn’t really a question of your technicals. It seems you now how to code. But it also seems you’re getting lost in the logic.

Take a piece of paper and a pencil, and step away from the computer. Write out the challenge in your own words, just an overview. Refer to the spec listed on the challenge page if you need to, but demonstrate you understand the concept.

Next, start breaking it down. Leave the language out, work on the logic still in your own words. Getting these concepts is key. If you can’t see the path through, how can you tell the browser what to do?

I’ve included a little bit of pseudocode to give you a nudge. This is not code, this is not pretty, this is not a solution – but it’s what I wrote out to help myself understand the “job specs”.

loop through each contact record {
  does the current contact firstName match the  name I've been given? {
    If yes,does the current contact actually have that property? {
      if yes, do something with that  property
    } else {
      the current contact, which IS the one I want, doesn't have that  property.
      What  should I  do here?
    }
  }
}
At this point, I have checked all the contacts, and none of them have that first name.
What should I do here?
2 Likes

Oh no… logic is my only weakness. :sweat_smile:

1 Like

Mine’s Kryptonite. :stuck_out_tongue_winking_eye:

That’s why I figured I’d suggest a starting outline for you, so you could maybe build your logic from that.

1 Like