I'm creating a little calculator. Part of this will allow you to input upto 4 numbers but you could just have 1,2 or 3 as well. I've got the code working except for when I only enter 1, 2 or 3 numbers I get a NaN result for the numbers I haven't entered.
How do I get rid of the NaN result?
my jQuery for splitting the inputted form data is -
var numbers = num4.split(" ");
var firstNumber = parseInt(margins[0], 10),
secondNumber = parseInt(margins[1], 10),
thirdNumber = parseInt(margins[2], 10),
fourthNumber = parseInt(margins[3], 10);
console.log(firstNumber, secondNumber, thirdNumber, fourthNumber);
var shorthand1 = parseInt (firstNumber, 10) * 1;
var shorthand2 = parseInt (secondNumber, 10) * 1;
var shorthand3 = parseInt (thirdNumber, 10) *1;
var shorthand4 = parseInt (fourthNumber, 10) *1;
and I just have
shorthand1 + shorthand2 + shorthand3 + shorthand4
as a result displayed in a div on the page.
The issues is if I enter "10 10 10" and not enter a fourth number I get a result of
10 10 10 NaN
Can I check for NaN and not get that result processed?