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 😊

Top comments (0)