var shops = [{
captain: "Tim",
chicken: 150,
coke: 200,
fries: 70,
set: 99,
},
{
captain: "Min",
chicken: 99,
coke: 77,
fries: 55,
set: 101,
},
{
captain: "Mike",
chicken: 105,
coke: 111,
fries: 75,
set: 130,
},
];
//陣列資料
var shopsTotal = shops.length;
console.log(shopsTotal);
for (var i = 0; i < shopsTotal; i++) {
if (shops[i].chicken > 100) {
console.log(shops[i].captain + "的店家有足夠 100 份炸雞");
shops[i].chicken -= 100;
console.log(shops[i].captain + "的店家還剩下 " + shops[i].chicken + " 份炸雞");
break;
}
};
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.