Result variable returning empty string

Tell us what’s happening:

The below code already works. I just need some further clarification on why my solution didn’t work. It basically looked like the code below except for the line 'result = lookup[val]. My original answer had that line like this 'lookup[val] = result. When it was like this no matter what argument was passed in the function it would return the default value of result, which is an empty string. I thought you could set them up either way? Why can’t you?

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

  result = lookup[val];

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

// Change this value to test
phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups

The assignment operator always store the value its the right in what is to its left
In this case you were giving value of "" to one of the properties of the object

1 Like