You could remove the loop and use a recursive function that calls out to a promise and waits till it resolves before it fires again.
The HTML children will not be added until all the alerts have been accepted.
var message = document.getElementById("message");
var clicksRemaining = 9;
const handleClick = () => new Promise(res => {
message.append(document
.createTextNode(`${clicksRemaining}) Es-tu près !!OUI!! ou !!NON!!`));
message.append(document.createElement('br'));
alert("Es-tu près");
res();
});
function non() {
handleClick().then(() => {
if (clicksRemaining --> 1) {
non();
}
});
}
document.getElementById('boutonNon').click();
<div id="divNon">
<button class="bouton boutonOui" id="boutonNon"
onclick="non()" value="reset">Non</button>
</div>
<div id="message"></div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…