Basic JavaScript - Profile Lookup

Tell us what’s happening:
Describe your issue in detail here.

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

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

Hi Daniel,

Are you struggling with anything?

i can not be a const variable when the loop needs to increment it.

It works with lookUpProfile("Akira", "likes") because that is the first object in the array so the loop never gets to the increment stage, which only happens after the loop body has run. The return in the loop body causes it to skip the increment stage so no error ever happens for that specific call.

If you tried using lookUpProfile("Sherlock", "likes") you will get an error.

Unfortunately, running the tests doesn’t throw an error in the output. But it does get logged to the browser console.

1 Like

I mean it’s my first coding and I am going through all these question and test but I feel like I’m not learn as much as I should

Hi Daniel,

Laslorg’s comment, solves your first main issue. Do you remember the difference between let and const?

I would focus on taking things slow and steady to start with. You’re doing the right thing by coming to the community though. Don’t be hard on yourself to start with, just keep absorbing JavaScript slowly and with an upfront knowledge that it may take time. It has taken me a lot of time to learn. I’ve been doing this course for 2 years on and off and I’m now only just at the projects stage.

I would suggest you become slightly more detailed in your description of the problem you are facing and that you don’t post as soon as you get an error, but begin by making written records of the problem and what you did to try to solve it. The day after after you can explain the problem in more detail and why your expectations weren’t met. That’s a better time to reach out.

Try to enjoy the process bud and keep doing what you’re doing :clap::clap:

Your comment makes me think you copied the solution. Also, most beginners will not do the return value || value expression on their own until later on.

If you are copying/pasting code you won’t really learn much. It would be better to try it on your own and then ask for help on the forum.

Thanks men, been really overthinking everything

1 Like

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