Basic JavaScript - Profile Lookup

Tell us what’s happening:
I am trying to write a recursive function to fix the problem. I am stuck and I don’t know what to put inside the “if” and “return” statements. Can I utilize two "If’ statements and have it still work?

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 (name <= firstName){
  if (prop <= 0) {
    return 1;
  } else {
    return lookupprofile(name, prop)
    }
  }
  // Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

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

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

I don’t understand this comparison

I’m not sure about this one either

This really isn’t a good fit for recursion

I don’t see how you envision the recursive logic working? I think a loop would be a more straightforward solution.

I tried the loop solution but it did not work.

The loop solution can work and is easier to get working than recursion.

If you show us what you tried, we can tell you what to fix.

Tell us what’s happening:
Still not working. tried creating a recursive function, did not pass the test. tried creating a for loop, still not passing the test

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


Your browser information:

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

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

please do not create duplicate topics for the same challenge.
I’ve merged your topics into one. (if you need to add any comments, just put them here)

I’ve updated my code but it is still not passing all tests.

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

const data = lookUpProfile(“Akira”, “likes”);

console.log(data)

why are you only checking for firstName?

What if the function call is:
lookUpProfile(“Kristian”, “lastName”)