Using Objects for Lookups.. what is wrong with this?

Tell us what’s happening:

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",
  };
  return lookup.val;
 
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup[alpha];

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

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

result= lookup[val];
or
var result=lookup[val];

I tried both yet not working!

yes, return results is given below the editing above line

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

  // Only change code below this line
  var lookup(val) = {

     "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[alpha];

oh, I was just trying. but still without the (val) not working!

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

  // Only change code below this line
var phoneticLookup = {

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

// Change this value to test
phoneticLookup[alpha];

why doesn’t this one work?

// 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[alpha];

Remove extra comma after frank

1 Like

still not working!

But I see your point, it shouldn’t be there.

Your test call to the function is causing the code to error out. It should be phoneticLookup(“alpha”);

1 Like

Also delete or change the very last line to use (“alpha”) instead of [alpha]

1 Like

phoneticLookup(lookup.alpha)