Profile lookup makes no sense

what am i missing? it looks like its skipping right past all of this!

function lookUpProfile(name, prop){
// Only change code below this line
  for (var x = 0; x < contacts.length; x++){
  if (name === contacts[x].firstName) {
      if (prop === contacts[x].prop) {
        return contacts[x][prop];
} else {
      return "No Such Property";
  } 
  }
    else {
    return "No Such Contact";}

Hello @bvernwashington, you should really format your code properly here on the forum so that others can better help you.

I am curious about your code here: can you elaborate on your logic?
What do you think your code will do?

For example in the test:

lookUpProfile("Kristian", "lastName")

with the above if check, what do you think will happen?

Hope this helps narrowing down your issues :slight_smile:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I didn’t know how to copy it over, so I did what I thought would work. I made it smaller because it looked to be taking over the entire page.

Explaining how to copy it over would have been more than enough.

That said, I don’t understand, why it’s is not checking the information being sent in. It should be responding with the proper output - but I’ve managed to cut it off somehow.

I don’t want to just copy it from the solution screen - that would defeat the purpose of learning.

@Marmiz has said where you can start looking for issues - try answering what they have said


Next time, if you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

As I have it, it looks to be skipping the function all together. I have the conditions met (I assume), but it is not responding.

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

// Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Mobile/15E148 Safari/604.1.

Challenge: Profile Lookup

Link to the challenge:

I don’t see any code that you’ve written.

The function you show, unedited, does exactly nothing. And returns undefined. What does your actual lookupProfile function look like?

You have created two topics about the same subject. I have combined them.

answer this other post please, what do you thing that line does?

sorry - my last message didnt have the code. I dont know how to tag you and copy my code into the response!

i have since played with it a bit, but i dont understand what im missing
.
without (prop === conntacts.prop) , its looking for “no such contact”. as soon as i add that line and the return - it just skips out completly.

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 x = 0; x < contacts.length; x++){
 if (name === contacts[x].firstName) {
     if (prop === contacts[x].prop) {
       return contacts[x][prop];}
     }  
else {return 'No Such contact'};
 



 

   
}// 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:79.0) Gecko/20100101 Firefox/79.0.

Challenge: Profile Lookup

Link to the challenge:

but what’s that line looking for? what is it doing?

can you say that in plain words?

It must exactly match what is being checked.

Explains why that popped up a few versions ago…

The solutions had a common comment

(contacts.hasOwnProperty(prop)) . I didn’t use it because the system would say it’s not a function…

contacts[i].prop is always undefined
but even if it wasn’t, could the value of the property be equal to the name of the property?

so after fighting with this all night, for some reason the “||” is grey. I have noticed that if its grey, its 'invisible. The only other symbol i have on my computer is the ‘pause’ button. otherwise i think it would work

contacts[i].prop is always undefined so you can’t use it in an if statement to check something

So for that have anything to do with the fact my computer does not “see the “||”? It’s grey and the function hops right over it.

(I’m on my ph so I can’t see my code)

where have you used the OR || operator? none of the code snippets you posted have it

When I tried it (a few variations ago). It would not work. I don’t think it’s in there now, but I was wondering why it was not being “seen” by the computer

please show your code you have questions about

the only way for it to not be seen is if it’s inside a comment