[Solved] jQuery doesn’t parseInt blank input as 0


AFTER UPDATE

You can use the unary operator. For example,

+$("#cash").val()

As in,

paidSoFar = (+$("#cash").val()) + (+$("#card").val());

BEFORE UPDATE

To answer your question specifically without going into details of all the other problems. In the following lines of code.

function remaining() {
  ...
  if (paidSoFar >= totalOwed) {
    ...
  } else {
    remaining = totalOwed - paidSoFar;
    ...
  }
}

If you follow the usage of remaining, you can clearly see that you are overwriting remaining to a number. So, the next time you try to use remaining(), you may be getting the following error in your JavaScript console.

Uncaught TypeError: number is not a function

And the following usage is also worrisome.

function remaining() {
    ...
    $("#changeOrRemaining").html(remaining);
    ...
}

This one is clearly an infinite loop.

Check How to open the JavaScript console in different browsers? for details to access your browser’s console.

3

solved jQuery doesn’t parseInt blank input as 0