Profile Lookup - Do While Loop Attempt Not Working

Profile Lookup - Do While Loop Attempt Not Working
0.0 0


Why is this code not working? I want to complete challenge with do…while loop.

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 i=0;
do {
if (contacts[i][“firstName”] === name && contacts.hasOwnProperty(prop)) {
return contacts[i][prop];
} else if (prop!==contacts[i][name]) {
return “No such property”;
} else {
return “No such contact”;
i++; } while (i<contacts.length);

// Only change code above this line

// Change these values to test your function
lookUpProfile(“Akira”, “likes”);


There’s no such thing as nested if loops.


Yes, sry, for loops is what I meant


You code has one small bug, and this is about contacts.hasOwnProperty(prop).

TIP: contacts itself is an array, so it may returns false for contacts.hasOwnProperty(prop), but maybe you were meaning check if current index of contact has that property?


Another bug is about when the asked contact was not found. Your func should return No such contact(read the challenge requirements again).

Your func returns "No such property" no matter if the contact or request property was found ot not.

TIP: have a var, and keep the contact existence with it. After the loop, check if contact was not found, so return No such contact, otherwise No such property.

I also suggest you use while over do-while.

Keep going on great work, happy programming.