Try this:
var count = Number( localStorage.visitCount );
if(isNaN(count)) { // <-- you forget bracker here
localStorage.visitCount = 1
} else {
localStorage.visitCount++
}
if( localStorage.visitCount >= 3 ) {
window.location.replace('http://stackoverflow.com')
}
Also, as Eric J. said in this answer, it looks like as logical mistake in first if
. It should be isNaN(count)
, not !isNaN(count)
. Explanation is in his answer.
Also, as gilly3 mentioned in his post you have to handle situation, when localStorage.visitCount
greater then 3.
if( localStorage.visitCount > 3 ) {
// handler for this situation
}