Tell us what’s happening:
I copied your code from the sample solution, but it doesn’t pass the test in your simulator
![]()
Your code so far
function lookUpProfile(name, prop) {
for (let x = 0; x < contacts.length; x++) {
if (contacts[x].firstName === name) {
if (contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else {
return "No such property";
}
}
}
return "No such contact";
}
I also tried my solution, it also fails with the same errors
function lookUpProfile(name, prop) {
// Only change code below this line
for (i = 0; i<contacts.length; i++) {
if (contacts[i].firstName === name ) {
if (contacts[i][prop]) {
return (String(contacts[i][prop]));
} else {return "No such property"}
}
}
return "No such contact"
// Only change code above this line
}
// running tests
lookUpProfile("Kristian", "lastName")
should return the string
Vos
lookUpProfile("Sherlock", "likes")
should return
["Intriguing Cases", "Violin"]
lookUpProfile("Harry", "likes")
should return an array
lookUpProfile("Bob", "number")
should return the string
No such contact
lookUpProfile("Bob", "potato")
should return the string
No such contact
lookUpProfile("Akira", "address")
should return the string
No such property
// tests completed
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Profile Lookup
Link to the challenge: