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

179
Visualizações
Mortgage Calculator/How much can I borrow

I have to repair this mortgage calculator, but I really don't understand why the calculation is not working. I need help to sort this out. Or at least someone to make me understand what is wrong with this function. (The calculator has an input for Applicants’ combined annual income and another input for Deposit. The calculator should show results for Maximum property value and Estimated monthly costs).

function PMT (rate_per_period, number_of_payments, present_value, future_value, type ) {
        var q = Math.pow(1 + rate_per_period, number_of_payments);
        return (rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));
}

jQuery(document).ready(function ($) {

        $(".input").keyup(function () {
            var annualIncomeInput = 0;
            var depositInput = 0;
            var annualIncome = 0;
            var deposit = 0;
            var mortgage = 0;
            var propertyValue = 0;
            var monthlyPayments = 0;
            annualIncomeInput = $('#annualIncome').val();
            depositInput = $('#deposit').val();
            annualIncome = parseFloat(annualIncomeInput.replace(/,/g, ''));
            deposit = parseFloat(depositInput.replace(/,/g, ''));
            if (annualIncomeInput && depositInput) {
                if ((deposit / 0.1 - deposit) >= (annualIncome * 4.5)) {
                    mortgage = annualIncome * 4.5;
                    propertyValue = mortgage + deposit;
                } else {
                    propertyValue = deposit / 0.1;
                    mortgage = propertyValue - deposit;
                }
                monthlyPayments = PMT(0.0307/12, 30*12, mortgage, 0, 0).toFixed(2);
            }
            
            propertyValue = parseFloat(propertyValue).toLocaleString();
            monthlyPayments = parseFloat(monthlyPayments).toLocaleString();
            $('#totalHowMuchCanIBorrow').text('£' + propertyValue);
            $('#estimatedCosts').text('£' + monthlyPayments);
            
        })
    })

If you need more details please let me know! Thank you!

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

0

This works maybe you find the error by comparing it to yours :) didn't changed anything just added the fitting html to it

function PMT(rate_per_period, number_of_payments, present_value, future_value, type) {
  var q = Math.pow(1 + rate_per_period, number_of_payments);
  return (rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));
}

jQuery(document).ready(function($) {
  //not sure how your html looks but maybe here you want $("input") and not $(".input") that selects all elements with the css class input that's maybe missing in the html
  $(".input").keyup(function() {
    var annualIncomeInput = 0;
    var depositInput = 0;
    var annualIncome = 0;
    var deposit = 0;
    var mortgage = 0;
    var propertyValue = 0;
    var monthlyPayments = 0;
    annualIncomeInput = $('#annualIncome').val();
    depositInput = $('#deposit').val();
    annualIncome = parseFloat(annualIncomeInput.replace(/,/g, ''));
    deposit = parseFloat(depositInput.replace(/,/g, ''));
    if (annualIncomeInput && depositInput) {
      if ((deposit / 0.1 - deposit) >= (annualIncome * 4.5)) {
        mortgage = annualIncome * 4.5;
        propertyValue = mortgage + deposit;
      } else {
        propertyValue = deposit / 0.1;
        mortgage = propertyValue - deposit;
      }
      monthlyPayments = PMT(0.0307 / 12, 30 * 12, mortgage, 0, 0).toFixed(2);
    }

    propertyValue = parseFloat(propertyValue).toLocaleString();
    monthlyPayments = parseFloat(monthlyPayments).toLocaleString();
    $('#totalHowMuchCanIBorrow').text('£' + propertyValue);
    $('#estimatedCosts').text('£' + monthlyPayments);

  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input class="input" id='annualIncome' type="number">
<input class="input" id='deposit' type="number">
<div id="totalHowMuchCanIBorrow"></div>
<div id="estimatedCosts"></div>

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