<html>
<body>
<h1>JavaScript Closures</h1>
<p>Counting with a local variable.</p>
<p id="demo">0</p>
<button type="button" onclick="myFunction()">Count!</button>
<script>
function myCounter() {
let counter = 0;
return function() {
counter++;
return counter;
};
}
const add = myCounter();
function myFunction(){
document.getElementById("demo").innerHTML = add();
}
</script>
</body>
</html>