I have this code here:
<script>
const stored = localStorage[location.href]
const number = stored || Math.floor(Math.random() * 6) + 2
document.getElementById("n1").innerHTML = number
if ( !stored ) localStorage[location.href] = number
</script>
<div>
The first number is <span id="n1"></span>.
</div>
That displays a random number between 2~6 and that saves that to the user's cache, so if he reloads the page the same number will appear again. But what I am trying to do now is to display a second number, and I am trying this:
<script>
const stored2 = localStorage[location.href]
const number2 = stored2 || Math.floor(Math.random() * 8) + 3
document.getElementById("n2").innerHTML = number2
if ( !stored2 ) localStorage[location.href] = number2
</script>
<div>
The second number is <span id="n2"></span>.
</div>
But the <span id="n2"></span> is display always the same number as in <span id="n1"></span>. I guess it has something to do with the local storage in the user's cache. How make it display 2 different numbers but keep storing those numbers in the user's cache so if he reloads the page the same 2 number would be displayed?
Thanks in advance