1 decade ago by peepli
Hello,
So I am trying to increment my localStorage value everytime a condition is true using the plugin provided by jsantell. But it doesn't seem to work
Below is my block of code where I try to implement this
for(var j = 0; j < inputArray.length; j++){
for(var k = 0; k < this.probsSolved.length; k++){
if( inputArray[j] == this.probsSolved[k] ){
this.storage.set(probSolKey, '' +parseInt(this.storage.get(probSolKey))+1);
console.log(this.storage.get(probSolKey));
if(this.storage.get(probSolKey) == "NaN".concat(totalProbToSolve)){
this.storage.set(achkey,1);
this.triggerAchievements(id,name);
}
}
}
}
So as localStorage only accepts strings, someone on StackOverflow suggested me to do parseInt and increment the value by 1 everytime the condition is met. So I want to increment my localStorageValue of probSolKey every time my if condition after inner loop executes to true.
So for the first time I get the value as NaN1 on my console.log. It's a weird value but for now I am just fine with it.
Next time again when my condition goes true my localStorage value stays at NaN1 and does not increment to NaN2.
I am sure my condition meets and I can reach the console.log everytime the condition is true but the value of probSolKey does not increment.
What could be the problem??
So I am trying to increment my localStorage value everytime a condition is true using the plugin provided by jsantell. But it doesn't seem to work
Below is my block of code where I try to implement this
for(var j = 0; j < inputArray.length; j++){
for(var k = 0; k < this.probsSolved.length; k++){
if( inputArray[j] == this.probsSolved[k] ){
this.storage.set(probSolKey, '' +parseInt(this.storage.get(probSolKey))+1);
console.log(this.storage.get(probSolKey));
if(this.storage.get(probSolKey) == "NaN".concat(totalProbToSolve)){
this.storage.set(achkey,1);
this.triggerAchievements(id,name);
}
}
}
}
So as localStorage only accepts strings, someone on StackOverflow suggested me to do parseInt and increment the value by 1 everytime the condition is met. So I want to increment my localStorageValue of probSolKey every time my if condition after inner loop executes to true.
So for the first time I get the value as NaN1 on my console.log. It's a weird value but for now I am just fine with it.
Next time again when my condition goes true my localStorage value stays at NaN1 and does not increment to NaN2.
I am sure my condition meets and I can reach the console.log everytime the condition is true but the value of probSolKey does not increment.
What could be the problem??