// check for cookies when window loaded
window.onload = displayWelcome();
// listen for click event on form submit button
document.getElementById('submit').addEventListener('click', setCookie, false);
// listen for click on reset button
document.getElementById('reset').addEventListener('click', reset, false);
//
document.getElementById('submit').addEventListener('click', checkPizza, false);
function setCookie() {
//take user name and date
var customerName = document.getElementById('name').value;
var nowTime = new Date();
var expiryTime = new Date();
expiryTime.setTime(nowTime.getTime() + 864000000);// + ten days
document.cookie = "name=" + customerName + ";";
document.cookie = "lastVisited=" + nowTime.getTime() + ";";
document.cookie = "expires=" + expiryTime.toUTCString() + ";";
}
function readCookie() {
// split cookie string into array of strings: "key = value"
var cookieValues = document.cookie.split(";");
// extract actual key and value from string and store in array (old cookie)
var oldCookie = [];
for(var i=0; i<cookieValues.length; i++) {
if (cookieValues[i].indexOf("name=") != -1) {
oldCookie.name = cookieValues[i].substring(5, cookieValues[i].length);
}
if (cookieValues[i].indexOf("lastVisited=") != -1) {
oldCookie.lastVisited = cookieValues[i].substring(13, cookieValues[i].length);
}
}
return oldCookie;
}
function displayWelcome() {
//read old cookie
var name = "";
var lastVisited;
var lastCookieValues = [];
lastCookieValues = readCookie();
//extract last visit date
var lastVisited = new Date(parseInt(lastCookieValues.lastVisited));
//create heading tag to display welcome message
var newNode = document.createElement("H1");
var welcomeMessage = document.createTextNode(
//display name, date and time from old cookie
"Hello " + lastCookieValues.name + ", your last order was on " + lastVisited.toDateString() + " at " +...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.