i have this code to sum 3 numbers so i+j+k but I get as result Nan
here is the code:
var i = req.param('1', null);
i = parseInt(i);
var j = req.param('2', null);
j = parseInt(j);
var k = req.param('3', null);
k = parseInt(k);
var r = i+j+k;
res.render('index', {result:r});
this is node based js
parseInt10toparseIntto ensure it parses the number as a decimal value and not e.g. hex (0x prefix) or octal (leading zero)rvariable beforei(var r = 0;)and then instead ofparsetIntinto the same variable everytime, parse it to yourrvariable doing a sum liker += parseInt(i)and repeat that forjandk.. try thatrvariable beforei..." Won't make any difference, see Poor misunderstoodvar(Although I always recommend doing allvarstatements at the top of the execution context, since that's where they happen anyway.)