• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

95
Views
Javascipt to count increment price for each tier

I am new to coding and currently touch the javascript part. I am facing a question about how to calculate the different tier prices and charges as shown in the image below.enter image description here.This is the code that I try myself which i is means the LOAN AMOUNT when i is equal to 1 it will use the next tier percentage to count and the i will +1 ag, but I am not sure is it correct or not... And should I add a EventListener to determine which tier the input now is?Sorry for my broken english.Thanks a lot!^_^

if(loan >= 500000 && loan < 1000000 && i==0) charge = 1% i = 1

if(loan >= 500000 && loan < 1000000 && i==1) charge = 0.8% i = 2

if(loan >= 2000000 && loan < 2000000 && i==2) charge = 0.7% i = 3

if(loan >= 2000000 && loan < 2000000 && i==3) charge = 0.6% i= 4

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not quite sure what your goal is, but if you want a system like tax brackets, where the loan amount is charged in portions based on the remaining money and where it fits in a tier it might look a little like this:

const getPercentageCharge = (amount) => {
  let loanAmount = amount;
  let i = [];
  let percents = [];
  
  loanAmount -= 500000; 
  i.push(1)
  percents.push(1)  
  if (loanAmount < 0) {
     return {i, percents}
  }

  loanAmount -= 500000; 
  i.push(2)
  percents.push(0.8)
  if (loanAmount < 0) {
     return {i, percents}
  }
   
  loanAmount -= 2000000; 
  i.push(3)
  percents.push(0.7)
  if (loanAmount < 0) {
     return {i, percents}
  }

  loanAmount -= 2000000; 
  i.push(4)
  percents.push(0.6)
  if (loanAmount < 0) {
     return {i, percents}
  }

  loanAmount -= 25000000; 
  i.push(5)
  percents.push(0.5)
  if (loanAmount < 0) {
     return {i, percents}
  }

  loanAmount -= 75000000; 
  i.push(0.5)
  percents.push(6)
  if (loanAmount < 0) {
     return {i, percents}
  }
}
console.log(getPercentageCharge(800000))

Otherwise, if you want the loan amount to be charged based on its total amount, it might look a little like this:

const getPercentageCharge = (amount) => {
  let loanAmount = amount;
  let i=1;
  let percent=1.0;
  
  if(loanAmount <= 500000) {
    percent = 1.0; 
    i = 1;  
  }

  if(loanAmount <= 1000000 && i==1) {
    percent = 0.8;
    i = 2
  }

  if(loanAmount <= 3000000 && i==2) {
    percent = 0.7;
    i = 3
  }

  if(loanAmount <= 5000000 && i==3) {
    percent = 0.6;
    i = 4;
  }
  
  if(loanAmount <= 7500000 && i==4) {
    percent = 0.5;
    i = 5;
  }
  
  if(loanAmount > 15000000 && i==5) {
    percent = 0.5;
    i = 6;
  }
  
  return {i, percent};
}

console.log(getPercentageCharge(800000))

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error