Reputation: 419
var pagenumber = localStorage["pageno"];
var sum = pagenumber + i;
display(sum);
In this case i am getting the output sum = 11 (when input pagenumber = 1 and i = 1) , But i require the output sum = 2
Upvotes: 0
Views: 304
Reputation: 368
You can use parseInt
to convert your strings to integers in JavaScript:
var sum = parseInt(localStorage["pageno"]) + parseInt(i);
display(sum);
Upvotes: 0
Reputation: 3308
Need to parse the "1" in localStorage to an integer using the built in parseInt funtion:
var pagenumber = localStorage["pageno"];
var sum = Number.parseInt(pagenumber) + i;
display(sum);
Upvotes: 2