Can anyone help me understand what is val is being used for here?

Tell us what’s happening:
Hey guys, actually I am having trouble understanding why are we using val here in
lookup[val] as val does not exist in lookup as property.

Your code so far

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

  // Only change code below this line
  var lookup={
  result = lookup[val];

  // Only change code above this line
  return result;

// Change this value to test

Your browser information:

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

Challenge: Using Objects for Lookups

Link to the challenge:

val will be the argument you give to the function when you call it. For example, if you call it like this:


then inside the function,

result = lookup["alpha"]

will run.

1 Like

so we are just passing lookup values to function through this?

Let’s go through this step by step.

You start by declaring a function phoneticLookup, using val as an argument.

You then declare a new object, lookup.

As you know, to find a specific key in an object you need to reference the corresponding name, in this example "alpha" to "foxtrot".

Then, you’re returning variable result, which is equal to one of the items in object lookup, according to the argument val.

val is not a property of lookup, it’s simply an argument, or a placeholder “value” for whatever real value you’re passing to function phoneticLookup.

1 Like

Thanks for taking the time to explain it in such an elaborative way, I understand now that it is just acting a placeholder for the value that we are passing to phoneticLookup

1 Like