Деньги к деньгам Помогите пройти

Помогите! Не могу пройти Деньги к деньгам,
Прошу о помощи :pray:

Код скиньте

var calculateDeposit = function (start, percent, months, isCapitalized) {
if (isCapitalized) {
var month = start + (start * ((percent/100) / 12));
for (var i = 2, sum = month; i <= months; i++) {
sum += month * ((percent/100)/12);
}
}
else {
var sum = start + (start * (((percent/100) / 12) * months));
}
return Math.round(sum);
}

поменяйте метод округления на Math.floor(sum);

var calculateDeposit = function (startMoney, percent, months, capit) {
if (capit){
var eachMonth = [startMoney];
for (i = 0; i < months; i++){
var newMoney = eachMonth[i] + (eachMonth[i] / 100 * percent / 12 );
eachMonth.push(newMoney);
}
eachMonth;
for (i = 0; i <= months; i++){
var sum = eachMonth[eachMonth.length - 1];
}
return Math.floor(sum);
}
else {
var sum = startMoney + ((startMoney / 100) * (percent / 12 * months));
return Math.floor(sum);
}
};

var calculateDeposit = function (sumDeposit, percent, countMonth, isCapital) {
var newDeposit = sumDeposit;
if(isCapital === false)
{
percent = percent/12 * countMonth;
newDeposit = sumDeposit + sumDeposit * percent/100;
}else{
for(var i = 1; i<=countMonth; i++)
{
newDeposit = sumDeposit + sumDeposit * percent/12/100;
sumDeposit = newDeposit;
}
}

return Math.floor(newDeposit);
};

По моему очень простой и понятный код получился:

код
let calculateDeposit = function (startMoney, percentYear, months, isCapitalized) {
  
  let percentMonth = (percentYear / 12) / 100
  let endMoney = startMoney
  
  for (month = 1; month <= months; month++) {
    if (isCapitalized) { 
      endMoney += endMoney * percentMonth 
    } else {
      endMoney += startMoney * percentMonth 
    }
  }
    
  return Math.floor(endMoney)
};
2 лайка

function playScore (itStart, itPercent) {
return monthPercent = itStart * (itPercent/12) / 100
}

function calculateDeposit(start, percent, time, capital) {

if (capital) {

for (let i = 0; i < time; i++) {
  start += playScore(start, percent) * 1
}

} else {
start += playScore(start, percent) * time
}

return Math.floor(start)

};

let calculateDeposit = function (deposit, percent, term, capital) {

if(!capital) {
return deposit + Math.floor(deposit * ((percent / 100) / 12) * term);
} else {
for (i = 1; i <= term; i ++) {
let income = Math.floor(deposit * ((percent / 100) / 12));
deposit += income;
}

return deposit;

}
};
Сводка

const culculatePercent = percent => percent / 12 / 100;

let calculateDeposit = function (deposit, percent, months, isCapitalized) {
  const percentYear = culculatePercent(percent)

  if (isCapitalized) {
    let capDeposit = deposit;
    let sumPercent = 0;
    for (let i = months; i > 0; i--) {
      capDeposit += percentYear * capDeposit;
    }

    return Math.floor(capDeposit);
  }
  
  return Math.floor(percentYear * months * deposit + deposit);
};