Mam funkcje, która wykorzystuje JSON.parse do przechowywania zmiennych między umiejącymi się stronami html
fragment kodu:
var randomNumber = [];
var randomWordPl = [];
var randomAngWord = [];
var randomWordAng = [];
var gameCounter;
var userInput;
var randomWordAng2;
var randomWordPl2
gameCounter = localStorage.getItem("gameCounter");
loopCounter = localStorage.getItem("loopCounter");
userInput = localStorage.getItem("userInput");
randomWordAng = JSON.parse(localStorage.getItem("randomWordAng"));
randomNumber = JSON.parse(localStorage.getItem("randomNumber"));
randomWordPl = JSON.parse(localStorage.getItem("randomWordPl"));
console.log("loopCounter:"+loopCounter);
console.log("randomNumber:"+randomNumber[loopCounter]);
console.log(randomWordAng);
console.log(randomWordPl);
// isEmpty();
if (loopCounter != randomWordAng.length) { //jezeli loopCounter nie jest rowny kontynuuj iteracja petli *w załozeniu do mamentu w którym nie bedzie rowna
$("#randomWord_wordPl").html(randomWordAng[loopCounter]);
if (userInput == randomWordAng[loopCounter]) {
$("#Logic_wordAng").html(randomWordAng[loopCounter]);
$("#Logic_mark").html("Dobrze");
$("#Logic_userInput").html(localStorage.getItem("userInput"));
$("#Logic_wordPl").html(randomWordPl[loopCounter]);//Nie poprawne wyswietlanie słowa nie do tekstu
randomWordAng2 = randomWordAng.splice(loopCounter, 1);
randomWordPl2 = randomWordPl.splice(loopCounter, 1);
JSON.parse(localStorage.setItem("randomWordAng",JSON.stringify(randomWordAng)));
JSON.parse(localStorage.setItem("randomWordPl",JSON.stringify(randomWordPl)));
localStorage.getItem("randomWordAng");
localStorage.getItem("randomWordPl");
loopCounter--;
loopCounter--;
gameCounter--;
localStorage.setItem("loopCounter",loopCounter);
localStorage.setItem("gameCounter",gameCounter);
}
ale problem jest w tym fragmecie
JSON.parse(localStorage.setItem("randomWordAng",JSON.stringify(randomWordAng)));
JSON.parse(localStorage.setItem("randomWordPl",JSON.stringify(randomWordPl)));
pierwsza funkcja działa bez problemu, ale 2 jest jakby zagłuszana przez te pierwsza w rezulatcie pokazuje sie tylko randomWordAng a randomWordPl jest pomijane i sie nie wykonuje jak mogę to naprawic ?