Basic JavaScript - Profile Lookup

Tell us what’s happening:
Describe your issue in detail here.

Hi! I need help with this project. This is my second time through the Basic JavaScript lessons and this time I decided to take notes as I go…though it doesn’t seem to be helping much. Here is my code so far…I basically wrote pseudocode and I know it’s not even close. Does anyone have any videos that explain this concept clearly? I am still struggling with for loops which is what I think I need here. I looked at the solutions a bit ago and saw that it seemed to use those, but I am not sure how to get it myself.

Your code so far

// Setup
const 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
if ("firstName" === name && prop is there) {
  return value
} if ("firstName" != name) {
  return "No such contact"
} else if prop != prop {
  return "No such property"
}
  // Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

Hello!

Have you checked on the freeCodeCamp YouTube channel? There may be something there.

Happy coding! :slight_smile:

This is not proper JS.

Ahh, I see, you have pseudo code mixed in with your JS.

Writing pseudo code like this to plan out your attack is great.

However, in this case, I would suggest starting with the loop. You could review the for loop lesson here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops

First, I would create your for loop so you can iterate over this array of objects and just figure out how to access and print each element you’ll need to compare.

1 loop, print out the firstName of each object, and build your if/then logic from there.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.