Profile Lookup - general issue

Tell us what’s happening:

So im running into the same issue over and over, i thought carrying on would resolve it. what does this line of code do? it comes up again and again and really struggle to understand how exactly “contact.length” has anything to do with looking up the contacts. how x++ (x=x+1) has anything to do with it.

(var x = 0; x < contacts.length; x++){

i dont know, ive been following the exercises and they just completely lost me about half way through the Basic Javascript curriculum.

on that note, is there a collection of coding exercises that i can go do to deepen my understanding of what has been learned so far? thanks a lot for any input

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("Akira", "likes");

Your browser information:

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

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

In regards to your specific question - data structures like arrays are indexed (ordered), meaning that each piece of data they store is associated with an index (a position). Indexes are from 0 to the length(i.e. length is just a property of arrays that tells you how many items are in the array at this moment) - 1 (i.e. first item in the array is associated with index 0, last item is associated with length - 1). This is why if you want to go through all the items in the array (and check something for each of them), you need a variable (i.e. “x”) that will represent the current index in each iteration of the for loop. Logically, the loop stops when it reaches an index higher than the index of the last item in the array.

With regards to x++, it is just a shorthand way to write x = x + 1. The feature is probably there because it is so handy for loops, where in the majority of cases you need to increment by 1.

General advice
I would suggest going through the exercises that you’ve solved again. Take your time and try to understand all the things that are going on (in the FCC examples as well). If something is not completely clear, either ask in the forum or do a bit of research(5-10 min) to see more examples of the specific aspect you are having trouble with.