[Solved] how to wait for user to click then console log variable


your code is not triggering event by clicking, and you should pass argument result in resolve

let onlyBtn = document.getElementById("onlyButton");

let result;

async function realMain() {
    await step().then((res) => {
        console.log(res);
    });
}

async function step() {
    return new Promise((resolve) => {
        onlyBtn.addEventListener("click", function () {
            result = "nice";
            resolve(result);
        });
    });
}

realMain();
<div>
    <button id="onlyButton">Run</button>
</div>

0

solved how to wait for user to click then console log variable