Created
July 15, 2020 05:03
-
-
Save whatrocks/a64067225f4f5e9c5b4eeff616c88a95 to your computer and use it in GitHub Desktop.
Print string array one char at a time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="lines"></div> | |
<script type="text/javascript" src="./slow.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lines = ["I am the first line", "I am second line!"]; | |
async function printLines() { | |
let el = document.getElementById("lines"); | |
for (let line of lines) { | |
let p = document.createElement("p"); | |
el.appendChild(p); | |
s = ""; | |
for (let char of line) { | |
await delay(100); | |
s += char; | |
p.innerText = s; | |
} | |
} | |
} | |
async function delay(ms) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
} | |
printLines(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment