I would like to be able to continue playing next time when you close the browser.
let counter = 0;
let countPerSec = 0;
let countPerFiveSec = 0;
let countPer0_5Sec = 0;
let limo_stand_plus = 1;
let limo_stand_kosten = 4;
let taxi_pro_sec = 1;
let taxi_kosten_sec = 5;
let gartenArbeit_all_five_sec = 25;
let gartenArbeit_werkzeug_kosten = 25 ;
let zeitungAustragen = 1;
let zeitungFirmenKosten = 500;
let mehrLimoStände = 0;
let mehrLImoStändeKosten = 1500;
let prestige_plus = 0;
let prestige_minus = 50000;```
CodePudding user response:
You can use:
localStorage.setItem(key, value);
Read more at: https://www.w3schools.com/jsref/prop_win_localstorage.asp
In your example:
// Set values:
localStorage.setItem("counter", counter)
localStorage.setItem("countPerSec", countPerSec)
localStorage.setItem("countPerFiveSec", countPerFiveSec)
localStorage.setItem("countPer0_5Sec", countPer0_5Sec)
localStorage.setItem("limo_stand_plus", limo_stand_plus)
localStorage.setItem("limo_stand_kosten", limo_stand_kosten)
localStorage.setItem("taxi_pro_sec", taxi_pro_sec)
localStorage.setItem("taxi_kosten_sec", taxi_kosten_sec)
localStorage.setItem("gartenArbeit_all_five_sec", gartenArbeit_all_five_sec)
localStorage.setItem("gartenArbeit_werkzeug_kosten", gartenArbeit_werkzeug_kosten)
localStorage.setItem("zeitungAustragen", zeitungAustragen)
localStorage.setItem("zeitungFirmenKosten", zeitungFirmenKosten)
localStorage.setItem("mehrLimoStände", mehrLimoStände)
localStorage.setItem("mehrLImoStändeKosten", mehrLImoStändeKosten)
localStorage.setItem("prestige_plus", prestige_plus)
localStorage.setItem("prestige_minus", prestige_minus)
// Read values:
localStorage.getItem("counter")
localStorage.getItem("countPerSec")
localStorage.getItem("countPerFiveSec")
localStorage.getItem("countPer0_5Sec")
localStorage.getItem("limo_stand_plus")
localStorage.getItem("limo_stand_kosten")
localStorage.getItem("taxi_pro_sec")
localStorage.getItem("taxi_kosten_sec")
localStorage.getItem("gartenArbeit_all_five_sec")
localStorage.getItem("gartenArbeit_werkzeug_kosten")
localStorage.getItem("zeitungAustragen")
localStorage.getItem("zeitungFirmenKosten")
localStorage.getItem("mehrLimoStände")
localStorage.getItem("mehrLImoStändeKosten")
localStorage.getItem("prestige_plus")
localStorage.getItem("prestige_minus")
CodePudding user response:
Create an Object and Store
let counter = 0;
let countPerSec = 0;
let obj = {counter, countPerSec}; localStorage.setItem('record', JSON.stringify(obj))