Hello! I am trying to use local storage to save one of my arrays, pokemonchosen.here is the code:
var pokemonchosen = [];
How would I make it to where if refresh or browser close, the array pokemonchosen stays like it is? But I have a weirder problem than others, pokemonchosen doesn't have a value until someone buys a pokemon, in which case:
pokemonchosen.push("Charmander");
How would I make it where sets local storage on buy pokemon? This is one of many functions for pokemon:
function buymagikarp() {
if(coins >= 100 ) {
swal("Success", "You bought 1 magikarp!", "success");
coins -= 100;
pokemonchosen.push("Magikarp");
document.getElementById("p1").innerHTML = "Coins: " + coins;
localStorage.setItem('coins', coins);
} else {
swal("Error", "Not enough balance", "error");
}
}
Thank you :-)
What I have tried:
if(pokemonchosen != undefined) {
var JSONReadyUsers = JSON.stringify(pokemonchosen);
localStorage.setItem('pokemonchosen', JSONReadyUsers)
}