I am working on an attempted log in feature to our application. They fail three times it kicks them out altogether. To keep count of how many times they attempt I thought I would use localStorage because I can easily manipulate it. However, I am having trouble incrementing the value when they fail to authenticate themselves.
At the top, I am setting the localStorage variable
JavaScript
x
2
1
localStorage.setItem("attempts", "0")
2
and then if the server returns an error, I am trying to increment that value.
JavaScript
1
6
1
if(errorCode === 4936){
2
var attempts = localStorage.getItem("attempts");
3
localStorage.setItem(attempts++);
4
console.log(attempts);
5
}
6
and obviously this is not working, but all I can find when I research is setting and getting the localStorage nothing about updating or changing. Any help would be wonderful!
Advertisement
Answer
And in some cases you have to add ++ before attempts:
JavaScript
1
6
1
if (errorCode == 4936) {
2
var attempts = parseInt(localStorage.getItem("attempts"));
3
localStorage.setItem("attempts", ++attempts);
4
console.log(attempts);
5
}
6