What am I doing wrong? uhhh

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 i=0; i < contacts.length; i++;){

if(contacts[i].firstName===name && contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else 
if(name!==contacts){
   return "No such contact";
}else{
   return "No such property";

}
// Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

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

Challenge: Profile Lookup

Link to the challenge:

This is an example of where a good code editor can help you, as you have several syntax errors which the editor would point out. You are missing an end square bracket on the contacts array. You are missing an end curly bracket on the lookupProfile function. You have a stray semi-colon in your for statement.

I would highly suggest you get a good editor (e.g. Visual Studio Code). It will help you find these simple (yet often hard to see) issues. And it is completely free!

2 Likes

Thanks for your help. I use brackets for a text editor. I wasn’t thinking to use it to check my code. I’ve been trying to find mistakes on my own.

Every developer can tell you a story about how a ‘second pair of eyes’ caught stupid little mistakes that they’ve been trying to find for hours. It’s impossible to find them all. If you are staring at a screen of code all day you will automatically miss things like this. Moral of the story is, there is absolutely no shame in using the appropriate tools to help you.

1 Like

Bracket is definitely a must!

1 Like