Profile Lookup Challenge, Done everything but only passing 2/5
See original GitHub issueThe problem is that the first if condition has a problem that I think is trivial but I can’t figure it out ath the same time …
Challenge Profile Lookup has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
//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(firstName, prop){
// Only change code below this line
for ( var i = 0; i < contacts.length; i++) {
if ( contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else if (firstName !== contacts[i].firstName) {
return "No such contact";
}
else if (contacts[i].hasOwnProperty(prop) === false) {
return "No such property";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Harry", "likes");
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Profile Lookup Challenge, Done everything but only passing 2/5
Challenge Profile Lookup has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.
Read more >freeCodeCamp Challenge Guide: Profile Lookup
Profile Lookup · Hint 1. Use a for loop to cycle through the contacts list. · Hint 2. Use a nested if statement...
Read more >Profile Lookup freeCodeCamp Challenge JavaScript - YouTube
In this video, I demonstrate and explain how to solve the ' Profile Lookup ' basic JavaScript challenge from www.freecodecamp.org.
Read more >Profile Lookup, freeCodeCamp Basic Javascript - YouTube
Show your Support, Buy a Sticker! https://believerationally.com/shopIn this challenge, we learn how to look through an array of contacts in ...
Read more >Profile Lookup - Free Code Camp - YouTube
In this tutorial called Profile Lookup, we iterate through an array of objects and test those objects to see if they fit specific...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this challenge is designedly bad. The three incorrect answers from your code were the ones that had property with value(s), weren’t they? For example, lookUpProfile(“Sherlock”, “likes”);. Well, when the for-loop runs, it will not iterate from 0 to contacts.length - 1. The value of i will only be 0. Do you see why? After the first run, there will be a return statement no matter what. Therefore, the for-loop (and the function) will end.
No matter how designedly bad the challenge is, there are solutions. Here is mine if you want to take a look at it
P.s: If you have coded in complied programming languages, such as C, C++, Java, etc. (I’m not sure if this is JavaScript or the compile that FreeCodeCamp is using), when you use if-else statement, there will/must always be an “else” at the end of this if-else statement (you has else if).
solution: function lookUpProfile(name, prop) { // Only change code below this line for (var p in contacts) { if (contacts[p].firstName === name) { if (!contacts[p].hasOwnProperty(prop)) { return ‘No such property’; } return contacts[p][prop]; } } return “No such contact”; // Only change code above this line }