Hey,
I got stuck (again) with an exercise.
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
for (var i=0; i < contacts.length; i++){
if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else if (contacts[i].firstName !== name){
return "No such contact";
}
else if(!contacts[i].hasOwnProperty(prop)){
"No such property";
}
}
}
// Only change code above this line
// Change these values to test your function
lookUpProfile("Harry", "likes");
I get following error message:
// running tests
"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
"Harry","likes" should return an array
"Akira", "address" should return "No such property"
// tests completed
Am I missing something obvious?
ps. I am completely new to programming and find the problem solving part of codin more and more fun, but the steep learning curve between some exercises can be demotivating. I believe coding is similar to learning a language or math, where you master it by practicing practicing practicing. Hence, I am missing this repeatable practicing of concept here at FCC, any tips where I could get more practice of the same concepts?