Using Objects for Lookups Help Me Out Here

Using Objects for Lookups Help Me Out Here
0

#1

I have no idea what I’m doing wrong here, and why I can’t advance. Your input here would be great.

r
Original Problem

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

  // Only change code below this line
  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
  }

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

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

Edit


// 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
phoneticLookup("charlie");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

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


#2

Your function is returning result which equals empty string.


#3

I see where you have created the lookup object which is fine. However, I do not see where you assign result the value received when accessing the lookup object with val. If you have forgotten how to access an object property with a variable, take a look at this previous challenge.


#5

What should it look like then?


#6

I don’t know what to assign to result. Why initialize result to empty string then assign result to something? What would your code look like?


#7

I already explained what you need to assign to result.


#8

Assign a value from the lookup object. val in the function is the name of the property you want to find in your lookup object. How do you access properties in objects? randelldawson mentioned previous challenge that can help you remind this.


#9

The argument phoneticLookup("charlie") is not defined in your switch expresaion to make the function responses a default message if the arguments not found
Use
break; default: result = "the message that you wanna to show" return result }


#10

@suhaybcabdulahi - The challenge is supposed to be converting the existing switch statement into an object lookup, not writing a switch statement.


#11

// 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”
};
var result = lookup[val]
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup(“charlie”);


#12

Bravo! It works, but you declared result twice.