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

75
Views
My Javascript function is not acting the way I expect it to

I am building an expense tracker app. The addTransaction function in my code looks like this:

function addTransaction(name, amount, type) {
    var name = nameinputEl;
    var amount = amountinputEl;
    var type = type;
    if (name !== '' && amount !== '') {
    var newTransaction =  {
        name: nameinputEl,
        amount: parseInt(amountinputEl),
        type : type
    };
    state.transactions.push(newTransaction);
    updateState();
    }
    else {
        alert('Invalid data! Please try again.');
    }

    nameinputEl.value = '';
    amountinputEl.value = '';
}
    
   

However when I add a new transaction, 2 weird things happen:

  1. The entire transaction-name input field is pushed to the transaction history list.
  2. The 'amount' value pushed to the transaction history is returned as $NaN.

Even when I input null values into the name and amount fields, the null values are still rendered in the UI despite the 'if' statement in the function.

What am I missing? Help.

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