Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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))

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda