Why the output is not being accepted?

Tell us what’s happening:
My code outputs correctly but is not being accepted as a solution

Your code so far
// running tests

function lookUpProfile(name, prop) {
for (let i = 0; i < contacts.length; i++) {
		if (contacts[i].hasOwnProperty(prop) && name === contacts[i].firstName) {
			return contacts[i][prop];
		}
	}
	for (let i = 0; i < contacts.length; i++) {
		if (contacts[i].hasOwnProperty(prop) && name !== contacts[i].firstName) {
			return 'No such contact';
		}
	}
	return 'No such property';
}

// Setup
let 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 (let i = 0; i < contacts.length; i++) {
		if (contacts[i].hasOwnProperty(prop) && name === contacts[i].firstName) {
			return contacts[i][prop];
		}
	}
	for (let i = 0; i < contacts.length; i++) {
		if (contacts[i].hasOwnProperty(prop) && name !== contacts[i].firstName) {
			return 'No such contact';
		}
	}
	return 'No such property';
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: Profile Lookup

Link to the challenge:

because your this segment doesn’t initiate if there is no property called ‘potato’

if (contacts[i].hasOwnProperty(prop) && name !== contacts[i].firstName) {
			return 'No such contact';
		}
1 Like