DEV Community

Cover image for πŸ‘¨β€πŸ’» Daily Code 52 | +1 & -1 Buttons in 🟨 JavaScript
Gregor Schafroth
Gregor Schafroth

Posted on

πŸ‘¨β€πŸ’» Daily Code 52 | +1 & -1 Buttons in 🟨 JavaScript

So today I just gave me a JS exercise so easy that I could do the whole thing without even opening ChatGPT once. And I was able to do it! It’s a totally oversimplified calculator that can only do +1 and -1. Perhaps I should try to do more complicated calculators as exercises in the future, but anyways, right now I am very happy with this one!

My Code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>+1 & -1 buttons</title>
</head>

<body>
    <button id="js-plus-one">+1</button>
    <button id="js-minus-one">-1</button>
    <div id="js-result">0</div>
    <script>
        let result = 0
        document.getElementById('js-plus-one').onclick = function () {
            result++;
            document.getElementById('js-result').textContent = result;
        }
        document.getElementById('js-minus-one').onclick = function () {
            result--;
            document.getElementById('js-result').textContent = result;
        }

    </script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Nothing complicated about this really. It was just all a syntax exercise. And I’m happy to report that I’m by now getting really familiar with this.

That’s it for today. See you in the next one 😊

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs