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

199
Views
number value return NaN in js

in this excercise i create a counter that has a number display and 2 button to lower and increase number. i assign number to parseInt(num) to convert num object to number. i use alert to check type of number. typeof(number) return number but number return NaN. please someone explain.[edit]reading comment, i was able to solve the problem. i have upadated the solution

var low = document.getElementById("low")
var add = document.getElementById("add")
low.addEventListener("click", function () {
    var num = document.getElementById("num")
    var number = parseInt(num.innerText)
    num.innerHTML = number - 1
})
add.addEventListener("click", function () {
    var num = document.getElementById("num")
    var number = parseInt(num.innerText)
    num.innerHTML = number + 1
})
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link rel="stylesheet" href="style.css"> -->
</head>
<body>
    <div class="container">
        <h1>counter</h1>
        <h1 id="num">0</h1>
        <div class="btn">
            <button id="low">lower count</button>
            <button id="add">add count</button>
        </div>
    </div>
    <script src="js.js"></script>
</body>
</html>

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

0

You are trying to parseInt(num) but num is DOM element - not number. You want its content. You can get it with .innerText.

const num = document.getElementById("num")
console.log(num);
console.log(parseInt(num));
console.log(parseInt(num.innerText));
<h1 id="num">0</h1>

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!