Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda