Var 0 Var Txt Blablablabla Var Speed 50 Function Typewriter Txtlength Documentgetelementby Q37251725

var i = 0;var txt = ‘Blablablabla’;var speed = 50;
function typeWriter() {if (i < txt.length) {document.getElementById(“demo”).innerHTML += txt.charAt(i);i++;setTimeout(typeWriter,speed);}}

Can you explain this code step by step.
thesetimeout() function is the one that I still dont get.


Answer


Please find theupdated solution:(with explanation) and output

<!DOCTYPE html><html><head><title>Page Title</title> <script type=”text/javascript”> //temp variable i to store the length of txt var i = 0; //text to append to demo var txt = ‘Blablablabla’; // speed in millisecs var

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.