My code gives correct output but not passing all tests

Tell us what’s happening:
My code is giving the correct output as shown by the console.log but I’m not able to pass all the tests.

Error output:
// running tests
“Kristian”, “lastName” should return “Vos”
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”]
“Harry”,“likes” should return an array
// tests completed

// console output
Kristian lastName
Akira likes
[ ‘Pizza’, ‘Coding’, ‘Brownie Points’ ]
Sherlock likes
[ ‘Intriguing Cases’, ‘Violin’ ]
Harry likes
[ ‘Hogwarts’, ‘Magic’, ‘Hagrid’ ]
Bob number
Bob potato
Akira address

I’m unable to figure out what exactly I need to fix in my code to pass the tests.

Can you help please ?

Your code so far

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 found = false;
console.log(name, prop );
for (var i = 0 ; i < contacts.length; i++){
    if ( contacts[i].firstName == name) {
        if ( contacts[i].hasOwnProperty(prop)) {
            found = true;
            return contacts[i].prop;
        } else {
            return "No such property";

if ( found == false){
    return "No such contact";
// 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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:

var “found” is not required. i’ve updated that. :slight_smile:

Look at the difference between what you are logging and what you are returning.

1 Like

argh! thanks a lot! :=)