The hell is wrong with it?

//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(name, prop){
// Only change code below this line
 for (var i = 0;i < contacts.length;i++){
     if (contacts[i].firstName === name){
         if (contacts[i].hasOwnProperty(prop)){
             return contacts[i][prop];
         } else {
             return "No such property";
         }
     } else {
         return "No such contact";
     }
 }
// Only change code above this line
}

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

i dont know what is wrong with it
Basic JavaScript: Profile Lookup

"Kristian", "lastName"

should return

"Vos"
"Sherlock", "likes"

should return

["Intriguing Cases", "Violin"]
"Harry","likes"

should return an array

"Bob", "number"

should return “No such contact”

"Bob", "potato"

should return “No such contact”

"Akira", "address"

should return “No such property”

i know what should return what. i think the problem is where im putting my else but i cant figure out where.everywhere is an error

spaces are missing here

 for (var i = 0;i < contacts.length;i++){

you are better using the two straight lines here

 } else {
             return "No such property";

and delete the else statments
you only need 2 returns
also maybe use a console that log with data? so it puts it out

thanks.i laughed my ass off :rofl: for this oohhh.

the spaces are not an issue, is just that you have all return statements inside the loop, so something is returned when i is 0 and only the first element of the array is checked , not the others

1 Like

thanks.i found out and fixed it