Profile Lookup i don't know why

Tell us what’s happening:

Your code so far


//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 j = 0; j<contacts.length; j++){
    if(contacts[j].firstname === name){
        if(contacts[j].hasOwnProperty(prop)){
            return contacts[j][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");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/

it keeps on telling me syntax error on the else statements that returns else{ return "No such contact"; }

If I properly indent your code, you will see the else does not belong where you have it.

function lookUpProfile(name, prop) {
  // Only change code below this line
  for (var j = 0; j < contacts.length; j++) {
    if (contacts[j].firstname === name) {
      if (contacts[j].hasOwnProperty(prop)) {
        return contacts[j][prop];
      }
      else {
        return "No such property";
      }
    }
  }
    else {
    return "No such contact";
  }


  // Only change code above this line
}

The for loop ends and then your next line is an else statement. You would need a corresponding if statement with that else for there not to be a syntax error. Think carefully about what you really need to be doing here (instead of an else statement).

i have tried thinking but it is to no avail

Do you need an else statement at all? If not, what would you do instead?

i can try to use the else if in place of the else statement

You don’t need any further conditional statements outside the for loop. If you loop through all the contacts array objects without the other two return statements executing, what does that tell you? If you can’t answer this question, then you need to write out your algorithm steps first to figure out the logic.