1 / 3
amogtech
2 / 3
mhk
3 / 3
ccg


<html>
<head>
<title>Adding and Reducing Function</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "addFun()">+</button>
<button type = "button" onclick = "redFun()">-</button>
<script>
var counter = 0;

var add = (function(){
return function(){
counter += 1;
return counter;
}
})();
function addFun(){
document.getElementById("demo").innerHTML = add();
}

var reduce = (function(){
return function(){
counter -= 1;
return counter;
}
})();
function redFun(){
document.getElementById("demo").innerHTML = reduce();
}
document.getElementById("demo").innerHTML = 0;
</script>
</body>
</html>


Share On:

What do you think?

Send us feedback!