JSFiddle - React, Tailwind, and code Playground

by Tilwin Joy

HTML

<form name="f1" onload="onload()">Gold:
    <input type="text" value='0' name="t1" id="a2" disabled>
    <br>
    <input type="button" value="Click me" id="a1" onclick="clickAdd()">
    <br>Jewels:
    <input type="text" value="0" name="g1" id="a3" disabled>
    <br>Cost: 50 Gold
    <input type="button" value="5 jewels" id="a4" onclick="click5()">
    <br>Cost: 100 Gold
    <input type="button" value="10 jewels" id="a5" onclick="click10()">
    <br>
</form>

JavaScript

function clickAdd() {
    console.log('click');
        //Detects if local stoage click count exists
    console.log(localStorage.getItem("clickcount"));
    if (localStorage.getItem("clickcount") == null) {
            localStorage.setItem('clickcount', 0);
            //Sets the clickcount to zero
        } 
    else {
            //If it already exists.    
            localStorage.setItem("clickcount", parseInt(localStorage.getItem('clickcount')) + 1);
            document.getElementById("a2").value = localStorage.getItem('clickcount');
        }
    }