I have a little problem with my code. If I click 2 divs they show a random Number, but if I click a third div. All my numbers have to remove but it isn't working. Can someone help me?
let mijnDivs = document.querySelectorAll("div")
let i = 0
while (i<mijnDivs.length) {
mijnDivs[i].addEventListener("click", toevoegen)
i++
}
function toevoegen(event) {
console.log("het werkt")
let nummer = randomNumber(1,9)
this.innerHTML = nummer
this.classList.toggle("zichtbaar")
if (this.classList.contains("zichtbaar").length === 2) {
console.log("yay")
}
}
function randomNumber (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Aucun commentaire:
Enregistrer un commentaire