使用对象查找,我看不到我的错误

问题描述 投票:0回答:0
// Setup
function phoneticLookup(val) {
    let result = "";
  
    // Only change code below this line
  
    const lookup = {
      "":undefined,
      "alpha": "Adams",
      "bravo":"Boston",
      "charlie":"Chicago",
      "delta":"Denver",
      "echo":"Easy",
      "foxtrot":"Frank",
    }
    const value = lookup[val]
    result += value;
    // Only change code above this line
    return result;
  }
  console.log(  phoneticLookup(""))

代码结果如我所料,应用程序是这样工作的,如果你将值 == 传递给对象的字符串,应用程序将返回属性的键,但控制台向我发送错误消息,但是如果我放一个“”,输出是未定义的,所以我想一切都很好,可能有什么问题?

// running tests
phoneticLookup("") should equal undefined
// tests completed
// console output
undefined
javascript algorithm object lookup
© www.soinside.com 2019 - 2024. All rights reserved.