Basic JavaScript: Using Objects for Lookups,help me

Basic JavaScript: Using Objects for Lookups,help me
0

#1
// 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");

#2

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.


#3

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 = {

  }

#4

// 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”);


#5

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.


#6

sir please correct the code and paste it here…plz


#7

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

#8

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