Your while loop is running immediately and without a break and will block the code from executing
you likely mean this
const btn = document.querySelector("button");
let clicked = false;
btn.addEventListener("click", () => {
console.log("clicked");
clicked = true;
})
let iId = setInterval(function() {
if (clicked) clearInterval(iId); // clear the interval
else console.log("I am waiting"); // continue the interval
}, 1000)
<button>Click ME!</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…