2021年1月3日星期日

how to set localstorage variable into a function

I have this function

function sumFood (tot,tab_cout){      var tot = 0;      for (var i=0; i<tab_cout.length;i++) {           tot += Number(tab_cout[i]);      }      localStorage.setItem('tot',tot);  }    sumFood (GLC,GLCT);   sumFood (LIP,LIPT);  

I would like that GLC, LIP go into localStorage (in place of tot) but for some reasons the result I get is undefined... what to do? (console.log gives me good result of tot)

https://stackoverflow.com/questions/65557152/how-to-set-localstorage-variable-into-a-function January 04, 2021 at 10:54AM

没有评论:

发表评论