<html>
<body>
<center id="output">
<button onclick="run()">Run</button>
<p>Output:</p>
</br>
</center>
</body>
</html>
button {
background: #ff4848;
color: #c2ffd9;
}
// Here, this func returns a Promise which is resolved after ms milisecond.
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function run() {
print('First');
await sleep(1000);
print('Second');
}
function print(msg) {
document.querySelector('#output').innerHTML += msg;
document.querySelector('#output').innerHTML += '</br>';
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.