i have a probably stupid question, but i cant figure it out.
In a piece of code below I have a global variable guestsTotal and event hadler where this variable is incremented by 1 by clicking button.
I'm trying to display in console some message when guestsTotal will be 12. But this doesn't work.
My friend said that this wouldn't work because event hadlers are asynchronous in JS. And my script was already executed.
So is there a way to do some actions when the value of guestsTotal will be 12?
let adultTotal = 0
let childTotal = 0
let babyTotal = 0
let guestsTotal = 0
adultButtonPlus.addEventListener('click', function (evt) {
adultTotal++
guestsTotal++
adultCounter.textContent = adultTotal
guestsInput.value = `${guestsTotal} guests`
})
if (guestsTotal === 12) {
console.log('message')
}