Day 3 of learning JavaScript: People Counter App - Increment Button
Today is my third day of learning JavaScript and I created the increment button for the people counter app while using functions and a few new things. I only did the increment button, because I haven't had much time today but in my opinion, it's important to stay with your habits and continue doing them every day. So even though it wasn't that much, I still did something.
First I created the function, and then I build In a few new commands so that the increment function is displayed on the website:
let countEl = document.getElementById("count") // selects the the HTML element by its ID
let count = 0
function increment(){
count = count + 1 // counter that increments by 1
countEl.innerText = count // countEl selects the HTML element and .innerText is selecting the content of the HTML element
// the current count now gets displayed as the content of the HTML element
console.log(count) // test to check the numbers in the console
}
And again, it's important to have the attribute onclick:"increment()" added to the HTML button, so that the button runs the function when you click it.
Here an example of it, so that you see it works (I still haven't applied CSS to the website):
Even though it wasn't much content today, I still hope I could share valuable information with you and I hope you guys learned something new.