Using Objects for Lookups - think it's right, not working

Tell us what’s happening:
I did exactly what I thought it was and looked at the hint, and it’s still not working.
what am i doing wrong?

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"
  };

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

// Change this value to test
 return = lookup[val];

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Since you didn’t link the challenge I’m not sure what’s asked.
But from what I can see inside the function you declare an empty string named result, then you return result still as an empty string.

Then outside of the function you say that return is equal to lookup[val], lookup is an object inside the function so you can’t reach that outside.
Also return is a statement that you can’t overwrite or sign values to. You can’t write var return = 2, since return is part of the JS language.

If you intend to call the function you need to write phoneticLookup(param), note that val is just the name of the val inside the function, what you pass is is what val will be inside the function scope.

I remember this challenge. So you have an Object with a bunch of keys and values, and phoneticLookup(val) is getting a string to use as that key.

So… within your phoneticLookup() function, how can you use val to find a value in lookup?

If I had an object like this:

var billTheCat = {
  "name":"Bill The Cat",
  "legs": "Last I checked",
  "hobbies": "Hacking furballs on people",
  "likes": "Opus",
  "dislikes": "liberals"
}

…How would I get to, for example, Bill’s “likes”? I have two options:

  • billTheCat.likes will give me that, but so will
  • billTheCat["likes"]

They access the same property. But in the second case, I can use a string as the property name. Can you see how that might help you?

Also, when you see “change this value to test” in that exercise, they mean “leave it a call to phoneticLookup(), but change the value you’re looking for.”