Is it possible if i use for loop in this case?


#1


var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item, quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
}
};


// scan each item 4 times
for(var x = 0; x < 15; x++){
    console.log(cashRegister.scan("item","quantity"));
}

//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

@jeffriandriyanto

var items=["eggs","milk","magazine","chocolate"];
// scan each item 4 times
for(var x = 0; x < items.length; x++){
    cashRegister.scan(items[x],4);
}

#3

Thankyou sir!!!!!!!!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.