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

74
Vistas
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
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