Coding Feature.

JS) Creating a site that counts +1 or -1. 본문

Programming Language/JavaScript

JS) Creating a site that counts +1 or -1.

codingfeature 2023. 1. 9. 01:48

I referred to the code that is on the Internet.

<!DOCTYPE HTML>
<html>
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>counting up or down</title>
</head>
 
<body style="text-align: center;">
    <button id="btn">+1</button>
    <button id="btn2">-1</button>

    <p id="display">0</p>
 
    <script>
        var count = 0;
 
        document.getElementById("btn").onclick = function () {
            count++;
            document.getElementById("display").innerHTML = count;
        }
        document.getElementById("btn2").onclick = function () {
            count--;
            document.getElementById("display").innerHTML = count;
        }
    </script>
</body>
 
</html>