Tell us what’s happening:
Hi,
Does anyone tried to replace the for loop of this exercise with recursion?
I tried but I think I’m very lost for do it correctly, even I don’t know if this is possible
I will appreciate if someone can tell me how far Im or if this is possible.
thx
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"]
}
];
var length = []
function factorial(x){
if(x <= 0){
return 0;
} else {
length.push(x - 1);
}
return length
}
console.log(factorial(contacts.length));
function lookUpProfile(name, prop){
// Only change code below this line
if(contacts[length].firstName === name) {
if(contacts[length].hasOwnProperty(prop)){
return contacts[length][prop]
} else {
return "No such property";
}
}
return "No such contact";
// Only change code above this line
}
console.log(contacts[length].firstName);
console.log(lookUpProfile("Harry", "likes"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Profile Lookup
Link to the challenge: