Tell us what’s happening:
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
var properties;
for (var i = 0; i < contacts.length; i++){
if(contacts[i].firstName === name ){
properties = contacts[i][prop];
console.log(name,properties); // the problem is here
}else{
return("No such contact");
}
}
return("No such property")
}
// Only change code above this line
var a = lookUpProfile("Harry", "lastName");
console.log(a);
Here even if name and prop is true, that line is not executing.
until i remove the else statement like this:
function lookUpProfile(name, prop){
// Only change code below this line
var properties;
for (var i = 0; i < contacts.length; i++){
if(contacts[i].firstName === name ){
properties = contacts[i][prop];
console.log(name,properties);
}
}
}
// Only change code below this line
lookUpProfile("Harry", "lastName"); //Harry potter
Challenge: Profile Lookup
Link to the challenge: