Here I declared a variable with value from local storage var yourLink = parseInt(localStorage.getItem('linkID'));
but the problem is when there is no value for the first time this is not working. So, I tried to add another if
statement where there is no value found then assign a value to the yourLink
variable. But couldn't do it. What can I try next?
Here I give the full code:
var link = ["https://www.facebook.com/", "https://stackoverflow.com/"];
var yourLink = parseInt(localStorage.getItem('linkID'));
localStorage.setItem('linkID', yourLink);
if ((parseInt(localStorage.getItem('linkID')))<= 7 ) {
yourLink = parseInt(localStorage.getItem('linkID')) + 1;
localStorage.setItem('linkID', yourLink);
yourLink = parseInt(localStorage.getItem('linkID'))
window.open(link[0], '_blank');
} else if ((parseInt(localStorage.getItem('linkID'))) >= 8) {
yourLink = parseInt(localStorage.getItem('linkID')) + 1;
localStorage.setItem('linkID', yourLink);
yourLink = parseInt(localStorage.getItem('linkID'))
window.open(link[1], '_blank');
yourLink = 0;
localStorage.setItem('linkID', yourLink);
}