0

javascript function:

//from javascript file1
   for(i=0;i<10;i++){
      setContent(i);
   }

//from javascript file2 where function is present
        setContent: function (content) {    
        var xy=0;
        xy = parseInt(xy + content);
        console.log(xy);

Above code is appending the content instead of adding

Divyam Solanki
  • 461
  • 2
  • 7
  • 25
  • The code you provided doesn't do what you claim. I'm sure you're passing a string instead, but you should take time to review the code you provide instead of just assuming it represents the problem you're having. –  Dec 09 '17 at 14:41
  • Your sample code works as expected. Provide more details please. – Codemole Dec 09 '17 at 14:50

1 Answers1

0

do,

xy = xy + parseInt(content);

instead of,

xy = parseInt(xy + content);

as by doing this xy is concatenated first then is parsed to integer

vibhor1997a
  • 2,336
  • 2
  • 17
  • 37