最后一行显示“总计为41.300000000000004”。我一直在repl.it中运行它。
var groceryList = [
{food: "Mangos", price: 3.56},
{food: "Grapes", price: 4.23},
{food: "Chicken", price: 10.98},
{food: "Sweet Potatoes", price: 7.94},
{food: "Asst. Nuts", price: 6.54},
{food: "Yogurt", price: 5.32},
{food: "Papya", price: 2.73}
];
function shopping(items){
console.log (items.food + " = " + items.price + ".");
}
var grocery;
var total=0;
for ( grocery in groceryList){
total=total+groceryList[grocery].price;
shopping(groceryList[grocery]);
}
console.log("The grand total is " + total);