对象键未定义

时间:2020-07-28 00:14:37

标签: javascript object key

这是我的代码。

function measureRequiredFruit(fruitTotals) {
  if (fruitTotals[bananas] > 3 && fruitTotals[strawberries] > 10){// if there are more than 3 bananas and more than 10 strawberries
    return 'We have enough fruit, with " + totalBananas + " bananas, and " + totalStrawberries + " strawberries';// return 'We have enough fruit, with {totalBananas} bananas, and {totalStrawberries} strawberries'
  }
  else{// otherwise
    return 'We do not have enough of both fruits';// return 'We do not have enough of both fruits'
  }
}

var result1 = measureRequiredFruit({bananas: 4, strawberries: 12});
console.log('should log "We have enough fruit, with 4 bananas, and 12 strawberries":', result1);

我正在尝试在我的函数measureRequiredFruit中使用bananas键,该键应为4。但是我收到一条错误消息,提示“香蕉未定义”。为什么会这样?

0 个答案:

没有答案