-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem38.js
More file actions
26 lines (18 loc) · 746 Bytes
/
problem38.js
File metadata and controls
26 lines (18 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//Calculate the average rate(%) of profit
function averageRateOfProfit(profits, invest ){
let totalProfit = 0;
for( let i = 0; i < profits.length; i++){
const index = i ;
const profit = profits[index];
totalProfit = totalProfit + profit;
}
const averageProfit = totalProfit / profits.length;
const averageInvest = invest / 2;
const averageRateOfProfit = (averageProfit / averageInvest) * 100;
const outputMessage = "Average Rate of profit is "+ averageRateOfProfit.toFixed(1)+"%";
return outputMessage;
}
const profitsList = [60000, 70000, 75000, 80000, 85000];
const totalInvest = 500000;
const profitRate = averageRateOfProfit(profitsList, totalInvest );
console.log(profitRate);