What's wrong with the code

  **Your code so far**
// Setup
const 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<4; i++){
if(name=contacts[i].firstName){return prop=contacts[i][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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62

Challenge: Profile Lookup

Link to the challenge:

You deleted the Tell us What’s Happening part of the post. I don’t know what you want help with.

Here is your code formatted so its more human readable:

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

// Only change code above this line
}

oh sorry!!
but i wanna know what wrong in the code and how can i correct it

Lmao!!
really sorry for that​:joy::joy:

Describing your problems is an important debugging step. How is your code broken? Why do you know it is broken?

Also, you have some strange syntax problems:

function lookUpProfile(name, prop) {
// Only change code below this line
  // Why var here? let is always better
  for (var i=0; i<4; i++) {
    // why name = ...?
    // = is for assignment
    if (name=contacts[i].firstName) {
      return prop=contacts[i][prop];
    } else {
      return "No such contact";
    }
  }
// Only change code above this line
}
2 Likes

sorry ! i didn’t get …
‘strange syntax’

Did you read the comments I wrote?

  • You shouldn’t use var

  • You shouldn’t be using = inside of an if statement condition

Annnnnd…

It doesn’t help you for me to just play debugger for you. Learning how to debug is important to learning coding.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.