1 / 4
Computer Service
2 / 4
Networking Service
3 / 4
Web Development Service
4 / 4
Software Development Service
TNW - ICT Solutions
  • Home
  • Available Courses 
  • Available Services 
  • Website Samples 
  • Search Log In
  • <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>