Skip to main content
rwmoved irrelevant stuff
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

When it loads it does not use the storage or it says Not a Number (NaN)

Website: https://button-presser.glitch.me

\$\pi^r 2\$

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

When it loads it does not use the storage or it says Not a Number (NaN)

Website: https://button-presser.glitch.me

\$\pi^r 2\$

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

When it loads it does not use the storage or it says Not a Number (NaN)

added 92 characters in body
Source Link

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

When it loads it does not use the storage or it says Not a Number (NaN)

Website: https://button-presser.glitch.me

\$\pi^r 2\$

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

Website: https://button-presser.glitch.me

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

When it loads it does not use the storage or it says Not a Number (NaN)

Website: https://button-presser.glitch.me

\$\pi^r 2\$

Source Link

How to use local-storage

So I have this game and I would like to have a save function. Here is my code below:

function SaveData() {
  localStorage.setItem('save', score);
  localStorage.setItem('save', btoa(JSON.stringify(score)));  
}
function LoadData() {
  score = window.localStorage.getItem('save');
  document.getElementById('demo').innerHTML = score;
}
window.onload = function()  {
LoadData();
} 

Website: https://button-presser.glitch.me