I created a script containing 2 functions, the first calculates the percentage of an array, while the other function calculates the sum of my percentage with my array. But when I call my functions the output where would be my Array Percentage is doubled
const Info_Buyer = {
Name_Buyer: 'John',
Spent_Rest: [50, 100, 300, 10, 80],
Tip: [],
Total_Spent: 0,
// The function stores the amount spent for each restaurant and tips depending on the amount spent
Cal_Tip: function() {
let n = 0
while (n < this.Spent_Rest.length) {
if (this.Spent_Rest[n] < 50) {
this.Tip.unshift(this.Spent_Rest[n] * 0.2);
} else if (this.Spent_Rest[n] > 50 && this.Spent_Rest[n] < 200) {
this.Tip.unshift(this.Spent_Rest[n] * .15);
} else {
this.Tip.unshift(this.Spent_Rest[n] * .1);
}
n++
}
return this.Tip
},
// The function sums the value of the tip and the amount spent on the order, showing the total expense as output
Cal_Total: function() {
let tip = this.Cal_Tip()
let n = 0
while (n < this.Spent_Rest.length) {
this.Total_Spent += this.Spent_Rest[n] + tip[n]
n++
}
return this.Total_Spent
}
}
total = Info_Buyer.Cal_Tip()
tip = Info_Buyer.Cal_Total()
console.log(total, tip);
Expected result

Cal_Total()callsCal_Tip(), which adds to theTip()array.this.Spent_Rest[n] is 50your code apply* .1( same forthis.Spent_Rest[n] is 200 or more