Tell us what’s happening:
I have been spending a lot of time on this one and couldn’t get it to pass. Then I looked up other people’s answers and theirs wouldn’t pass either.
Any hints or directions where I might be going wrong please let me know. I have tried everything that I know of.
When I don’t declare “var firstName;” I get firstName not defined - yet no other answers I’ve seen have to declare this.
When I do declare it I get tests failing:
// running test
“Kristian”, “lastName” should return “Vos”
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”]
“Bob”, “number” should return “No such contact”
“Akira”, “address” should return “No such property”
// tests completed
Still a beginner so please keep your directions somewhat simple.
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 firstName;
> 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";
> }
> }
> }
> return "No such property";
>
> // Only change code above this line
> }
// Change these values to test your function
lookUpProfile("Akira", "likes");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup