Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Simple Counter Javascript

Today I'm working on making a simple counter with HTML / CSS and JS.

My javascript isn't working and I don't know why.. I read a lot on the internet and tried to add "async" but it seems that my code needs a review

let counter = document.getElementById('counter');
let increaseButton = document.getElementById('increase');
let decreaseButton = document.getElementById("decrease");
let resetButton = document.getElementById("reset");
let count = 0;
function functionIncrease() {
 count ++;
 counter.innerHTML(count);
 color();
}
function functionDecrease() {
 count--;
 counter.innerHTML(count);
 color();
}
function functionReset() {
 count = 0;
 counter.innerHTML(count);
 color();
}
function color() {
 if (count > 0) {
 counter.style.color = "green";
 } else if (count > 0) {
 counter.style.color = "red";
 }
}
increaseButton.addEventListener("click", functionIncrease());
decreaseButton.addEventListener("click", functionDecrease());
resetButton.addEventListener("click", functionReset())
<main>
 <h1>My Simple Counter</h1>
 <p id="counter">0</p>
 <div class="button">
 <button id="decrease">Decrease</button>
 <button id="reset">Reset</button>
 <button id="increase">Increase</button>
 </div>
</main>

I think it's just a stupid error, but I really need your help !

Thank you!

Answer*

Draft saved
Draft discarded
Cancel
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Oct 2, 2022 at 2:46

default

AltStyle によって変換されたページ (->オリジナル) /