Basic JavaScript: Using Objects for Lookups,help me

// 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 lookup[val];
}

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

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

1 Like

See the following line in the code?

// Only change code above this line

You did follow it’s instruction, so you are failing a test. Instead of changing the return statement, assign a value to result instead above this line.

Also, you closed off your lookup object prematurely (see below).

  var lookup = {

  }

// 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 lookup[val];
}
// Change this value to test
phoneticLookup(“delta”);

You are still not following the instructions. Like I said before in my previous reply, do not change the return statement. Instead, assign a value to result instead above this line.

sir please correct the code and paste it here…plz

No, you must learn to read the instructions and do as they say. Do not change any code below the line specified below. Instead, assign lookup[val] to the result variable above the line specified below.

// Only change code above this line

Done sir thnx alot…:smile::smile::smile::smile: