Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. var bills = {
  2. billAmounts: [124, 48, 268, 180, 42],
  3. allTips: [],
  4. totalPaid: [],
  5. calcTip: function () {
  6. for (var i = 0; i < this.billAmounts.length; i++) { //runs through each interger in array
  7.  
  8. if (this.billAmounts < 50) {
  9. this.allTips.push(this.billAmounts[i] * 0.20);
  10. } else if(this.billAmounts > 50 < 200) {
  11. this.allTips.push(this.billAmounts[i] * 0.15);
  12. }else{
  13. this.allTips.push(this.billAmounts[i] * 0.15);
  14. }
  15. }
  16.  
  17. this.totalPaid.push(this.billAmounts[0] + this.allTips[0])
  18. this.totalPaid.push(this.billAmounts[1] + this.allTips[1])
  19. this.totalPaid.push(this.billAmounts[2] + this.allTips[2]
  20. this.totalPaid.push(this.billAmounts[3] + this.allTips[3])
  21. this.totalPaid.push(this.billAmounts[4] + this.allTips[4])
  22.  
  23.  
  24. for (var i = 0; i < this.billAmounts.length;i++){
  25. return this.totalPaid.push(this.billAmounts[i] + this.allTips[i]);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement