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!
counter.innerHTML is not a function, but a scalar property:counter.innerHTML = count. Though sincecountis not HTML,textContentwould be better:counter.textContent = count. EDIT: Also what Luis said.innerHTMLis not a function- its a property....socounter.innerHTML = "Foo";