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?
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
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
}