JSFiddle - React, Tailwind, and code Playground

by jkneb

JavaScript

function showFlash( howManyTimes ){
    var counter = getCookie('counter');
    if (!counter) {
        counter = 1; // if the cookie was not found, it's the first visit
        writeFlash();
    }
    else if (counter <= howManyTimes-1){
        counter = parseInt(counter)+1; // else increment the counter
        writeFlash();
    }
    else {
        counter = parseInt(counter)+1;
        closeFlash();
    }
    // set the new cookie
    setCookie('counter', counter, 365);
}

// Show flash 2 times
showFlash(2);