0

I currently have some code like this:

function markAlert() {
    if (qnsAnsd == 4) {
        alert("You got " + mark + "/4! Refresh page if you want to try again.")
    };
}

function addEval() {
    var addMrknElem = document.getElementById('q__add-mrkn');
    qnsAnsdCntr();
    document.getElementById('q__add-btn').disabled = true;

    if (document.getElementById('q__add-ans').value == addSoln) {
        addMrknElem.innerHTML = "Your answer is correct!";
        markCntr();
    } else {
        addMrknElem.innerHTML = "Your answer is incorrect. The correct answer is " + addSoln + ".";
    }

    markAlert();
};

Basically title... I want the alert in markAlert() to pop up after the the .innerHTML takes effect.

1 Answers1

0

just wrap your alert() method in the setTimeout See the example below.

setTimeout(() => { markAlert() }, 1000);

Here, 1000 means 1 second so this markAlert() will be invoked after 1 second. you can change this value to 500 means half a second too.

MD M Nauman
  • 421
  • 4
  • 10