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

212
Views
Why is the value NaN

when I console log the nemo element it appears to be NaN. I have tried adding Number() to certain objects but it has made them undefined. Here is my JS

function newSum(elem) {

  console.log(elem.value)
  var sum = elem.parentElement.parentElement.children[5];

  var price = elem.parentElement.parentElement.children[2].textContent;

  sum.textContent = Number(price) * Number(elem.value);

  var sum = document.querySelectorAll(".summing");

  for (num of sum) {
    tota_sum.push(Number(num.textContent));
  }

  console.log(tota_sum);

  var overall = document.querySelector("#overall");

  var nemo;

  for (i = 0; i < tota_sum.length; i++) {
    nemo += Number(tota_sum[i]);
    console.log(nemo);
  }

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The default value without assignment is always undefined, and undefined + a number is NaN. Therefore, you need to initialize nemo value. In your case, it should be

var nemo = 0;

Full code

function newSum(elem) {

  console.log(elem.value)
  var sum = elem.parentElement.parentElement.children[5];

  var price = elem.parentElement.parentElement.children[2].textContent;

  sum.textContent = Number(price) * Number(elem.value);

  var sum = document.querySelectorAll(".summing");

  for (num of sum) {
    tota_sum.push(Number(num.textContent));
  }

  console.log(tota_sum);

  var overall = document.querySelector("#overall");

  var nemo = 0;

  for (i = 0; i < tota_sum.length; i++) {
    nemo += Number(tota_sum[i]);
    console.log(nemo);
  }

}
about 4 years ago · Juan Pablo Isaza 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!