Create a key that saves the previous value; and I want to add the old value to the new value (all entered by the same input);
for example: I have 5 and when I enter 2 I want to obtain 7;
But it only replaces the value, for example: if I enter 5 as the 1st value, it saves it; When entering 2 it replaces 5 and the sum returns 4 as the final result and if I enter 3 a 6.
I hope the question is understandable thank you very much in advance for the help
function assert() {
let valorDeInput = document.getElementById('btn2').value;
localStorage.setItem('name_user', valorDeInput);
let user = localStorage.getItem('name_user');
let suma = parseFloat(' valorDeInput') + parseFloat (user);
document.getElementById('cuadrado').innerHTML = suma;
}
I want to get the sum of the 2 values and not have it replaced
It is replaced because you are saving the new value before you get it. Ideally, you would get the value of storage, add it up, and finally save the result.