Testing Objects for Properties: Lost in this entire section

Testing Objects for Properties: Lost in this entire section
0

#1

here is the example:

var myObj = {
  top: "hat",
  bottom: "pants"
};
myObj.hasOwnProperty("top");    // true
myObj.hasOwnProperty("middle"); // false

I copied and pasted the example and just changed the values and it did not work, I am lost.
I also looked up the hint and people were using if/else if statements, but that didnt seem correct. What is the correst way to do this?


#2

hi
first you have to check if object (myObj) has the given property name - u can use myObj.hasOwnProperty(propname) method. Next if myObj.hasOwnProperty(propname) will be true u have to return property value if false return “Not Found”


#3

I am sorry but I did not understand this explanation.


#4

Can you break it down for me…


#5

Can you copy/past your most current attempt to code a solution to this challenge? It would help us to better assist you.


#6

This is the setup:


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


This is the answer:

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