You've used theResult === 0
where you should have used theResult = 0
.
The ===
is for comparisons. When you want to change the value of a variable, you use the assignment operator =
.
Like @zzzzBov said, the simplest thing to do is replace the whole thing with
theResult = isFinite(theResult) && theResult || 0; // updated
That glosses over the subtleties of NaN
however; if the user is finished and the result really is NaN
, showing that as 0
is not really correct.