Hello, i was seeing if someone can help me out

Tell us what’s happening:
Hello everyone! I noticed that var lookup is greyed out, and it seems to not be “declared”. Soi was seeing if someone can help me figure out why it says that, and how i can fix it. Thanks!

  **Your code so far**

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {
  "alpha": "Adams",
  "bravo": "Boston",
  "charlie": "Chicago",
  "delta": "Denver",
  "echo": "Easy",
  "foxtrot": "Frank"
};
  phoneticLookup["charlie"];
  result = phoneticLookup;

// Only change code above this line
return result;
}

phoneticLookup("charlie");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38

Challenge: Using Objects for Lookups

Link to the challenge:

Your problem may be here - your variable is named lookup but you’re looking…somewhere else?

But also, why are you explicitly looking up “Charlie”? Remember, you have the val parameter to play with.

Ah i see. I’m a bit confused by the instructions it says to look up val eventhough it seems like val isn’t in the object?

val is the name given to the variable defined here:

Now, when the function is called (like phoneticLookup("charlie") ), val references the value being passed in. "charlie', in this case.

So you’re right, val isn’t in the object, but the value val references…might be.

Thanks for responding! Interesting, this is what i have so far. And i think I see what you mean with "charlie"
however when i tried to assign the corresponding string to result, i might be messing up somewhere because i don’t think it’s working.

// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };

    lookup["charlie"];
    result = "Chicago";

  // Only change code above this line
  return result;
}

phoneticLookup("charlie");

You’re missing the point of passing parameters to a function and using the arguments (in this case val) within the function.

Here you are just hard coding the result you want without using the lookup variable.

The following will cause a syntax error:

Your function is literally just returning the string “Chicago”, it is functionally identical to doing this.

function phoneticLookup() {
    return "Chicago";
}

You are hardcoding the key value for the lookup. You should be using the function parameter val as the key value. Then return the value the lookup evaluates to.

function getLastName(firstName) {
  const lookup = {
    'John': 'Doe'
  }
  return lookup[firstName]
}

console.log(getLastName('John')); // Doe

In the case of this challenge, the test expects to find return result; in the code so you can’t just return the lookup value as in the example above.

1 Like

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