I'm just learning. Why does the 'tarifComm' value that I pass to the 'calcCondition' function become NaN. it doesn't let me calculate. how can i fix this problem?
input data
const input = 700000, const step = 3, let tarifComm = 0, let tempInput = input
array
const mass = [
{
"step": "1",
"min": "0",
"max": "150000",
"percent": "0.75",
"fix": "79"
},
{
"step": "2",
"min": "150001",
"max": "500000",
"percent": "1.5",
"fix": "79"
},
{
"step": "3",
"min": "500001",
"max": "2000000",
"percent": "2.5",
"fix": "79"
},
{
"step": "4",
"min": "2000001",
"max": "99999999",
"percent": "4",
"fix": "79"
}]
function dividing the calculation into parts
function calcStep() {
for(let i = 0; i < step; i++) {
console.log(`комиссия в начале пути ${tarifComm}`)
console.log(`создан ${tempInput}`)
if (tempInput > mass[i].max) {
tarifComm += calcCondition(i, tarifComm)
console.log(`комиссия на ${i+1} шаге: ${tarifComm}`)
tempInput = tempInput - mass[i].max
console.log(`изменен в макс ${tempInput}`)
} else if (tempInput < mass[i].max) {
console.log(`комиссия в мин: ${tarifComm}`)
console.log(`остаток в мин ${tempInput}`)
tarifComm += tempInput / 100 * mass[i].percent
}
}
tarifComm += Number(mass[step].fix)} calcStep()
and calculation function
function calcCondition(i, tarifComm) {
console.log(`комиссия попавшая в расчет ${tarifComm}`)
if (mass[i].free && !mass[i].percent) {
tarifComm += 0
} else if (!mass[i].free && mass[i].percent) {
tarifComm += mass[i].max / 100 * mass[i].percent
}}