Please help me The question is to calculate tip and total amount paid by a man using object and loop. bill Amount given : 124, 48, 268, 180, 42 (all id $) Though it doesn't matter
- Create an object with an array for the bill values
- Add a method to calculate the tip
- This method should include a loop to iterate over all the paid bills and do the tip calculations
- As an output, crater 1 array containing all tips and another array containing final paid amount.
let billValue = {
tipArray: [],
totalArray: [],
bill: [124, 48, 268, 180, 42],
tipCalc: function() {
for (let i = 0; i < this.bill.length(); i++) {
switch (true) {
case this.bill[i] < 50:
tipValue = (20 / 100) * bill[i];
totalValue = tipValue + this.bill[i];
tipArray.push(tipValue);
totalArray.push(totalValue);
break;
case this.bill[i] > 50 && this.bill[i] < 200:
tipValue = (15 / 100) * bill[i];
totalValue = tipValue + this.bill[i];
tipArray.push(tipValue);
totalArray.push(totalValue);
break;
case this.bill[i] > 200:
tipValue = (10 / 100) * bill[i];
totalValue = tipValue + this.bill[i];
tipArray.push(tipValue);
totalArray.push(totalValue);
break;
default:
}
}
}
}
console.log(billValue.tipArray);
console.log(billValue.totalArray);