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
req.param('2', null)returnsnullif the parameter is not specified.You then call
parseInt(null), which givesNaNIf you add any number with
NaN, you getNaN.Use
req.param('2', 0)instead