Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!