Using objects return for lookup

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

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

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

phoneticLookup("charlie");

How do i get this script to properly return the values.

The challenge has already a pretty good hint imho:

Use it to look up val and assign the associated string to the result variable.

You have to make sure that result variable holds the right value.
With the code you have it’s always an empty string.

Hope this helps :sparkles:

ok, so does this mean i have to put something like:
“val”=" "
or something? Cause i really don’t understand :sob:

What exactly is confusing you?

How to assign to a value to a variable?
Or how to use an object as a lookup table?

the part of assigning a value to a variable

That’s a very core part of programming in general.
If it’s not too clear I suggest you to step back a moment and review your knowledge and maybe the past lessons.

Anyway in JS the = operator assign a value on the right, to the variable on the left.
So

var x  =  10

Can be read as assign the value 10 to variable named ‘x’

Other examples:

var z = "foo" // assign string 'foo' to variable z
var x = 1 // assign 1 to variable x
var y = 2 // assign 2 to variable y
n = x + y // assign the computation of x + y to variable n

// and of course re-assign
x = "new value" // assign "new value" to variable x

You can get all info here:

Ok :grinning:
if you dont mind me asking, how do i use an object as a lookup table?

That’s what is explained in the challenge.
What is it that you find hard to understand?

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