JSFiddle - React, Tailwind, and code Playground

by Peadar Ó Duinnín

HTML

<title>Pizza</title>
        <link href="main.css" rel="stylesheet" type="text/css">
        <script type="text/javascript">
            function redraw() {
                //alert ("hello from redraw");
                var pizzaPrice = 0;

                pizzaImageSize = 250; // default to large
                pizzaBasePrice = 12;
                pricePerTopping = 1;

                if (document.getElementById('small').checked==true) {
                    pizzaImageSize = 100;
                    pizzaBasePrice = 6;
                    pricePerTopping = .5;
                }

                if (document.getElementById('medium').checked==true) {
                    pizzaImageSize = 180;
                    pizzaBasePrice = 10;
                    pricePerTopping = 1;
                }
                document.getElementById('image1').height=pizzaImageSize;
                document.getElementById('image1').width=pizzaImageSize;
                document.getElementById('image2').height=pizzaImageSize;
                document.getElementById('image2').width=pizzaImageSize;
                document.getElementById('image3').height=pizzaImageSize;
                document.getElementById('image3').width=pizzaImageSize;
                document.getElementById('image4').height=pizzaImageSize;
                document.getElementById('image4').width=pizzaImageSize;
                document.getElementById('image5').height=pizzaImageSize;
                document.getElementById('image5').width=pizzaImageSize;
                document.getElementById('image6').height=pizzaImageSize;
                document.getElementById('image6').width=pizzaImageSize;
                document.getElementById('image7').height=pizzaImageSize;
                document.getElementById('image7').width=pizzaImageSize;

                // do the toppings
                howManyToppings = 0;

                if (document.getElementById('anchovies').checked==true) {
                   ...

CSS

img {
    position: fixed;
    right: 100px;
    top: 100px;
}

input:invalid {
    background-color : #ff0000;
}

input:valid {
    background-color : #99ff99;
}

JavaScript

// 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 " +...