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

146
Visualizações
Multiplying two numbers giving NaN

I am creating a loan calculator in which the user must first select the type of calculation he wants. Then after filling the value, the answer's textnode updates. But when I am multiplying two values, it gives me NaN. I have tried console log both values separately and both are returning true values. I don't know what I am doing wrong.

class Calculation{
    constructor(a,b){
        this.a = a;
        this.b = b;
    }
    multiply(a,b){
        return a*b;
    } } 

document.querySelector('#cal-form').addEventListener("submit", function(e){
        const loaninput = parseInt(document.querySelector('#loan_val').value);
        const interestinput = parseInt(document.querySelector('#interest_val').value);
        const cal = new Calculation;
        const result = cal.multiply(loaninput,interestinput);
        console.log(result);
        e.preventDefault();
         });
about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

it giving right number on my side:

class calculator{
    constructor(a,b){
        this.a = a
        this.b = b
    }
    muliply(a,b){
        return a*b
    }
}

let a = new calculator()
console.log(a.muliply(2,3));

about 4 years ago · Santiago Gelvez Relatório

0

Any number multiple with NaN give the result is NaN.

You should log your loan_val and interest_val and ensure that these values can be convert to valid integer value by parseInt.

I think one of your input after parseInt return NaN.

about 4 years ago · Santiago Gelvez Relatório

0

should be this: const cal = new Calculation();

Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

about 4 years ago · Santiago Gelvez 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