JavaScript always shows 0

My JavaScript function always returns 0 when summing two values. Below is my updated code. Any suggestions to fix it?

<!DOCTYPE html>
<html>
<body>
  <input type="text" id="valueA">
  <input type="text" id="valueB">
  <button onclick="sumValues()">Add</button>
  <script>
    function sumValues() {
      var a = Number(document.getElementById('valueA').value);
      var b = Number(document.getElementById('valueB').value);
      alert(a + b);
    }
  </script>
</body>
</html>

The code you posted is correct for summing two numbers, so the issue might be elsewhere. If the inputs are empty, converting an empty string to a number will return 0, which might explain why you always get 0 when nothing is entered. I encountered a similar situation when I didn’t validate user input. Consider adding checks or using parseFloat if you require decimal precision. Additionally, test by hardcoding values to isolate the problem. This helped me find that the unexpected values were coming from input defaults rather than the logic itself.