{Solved}Why not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
23rd Nov 2018, 8:45 AM
B.D
B.D - avatar
4 Answers
+ 8
You tried to read the value from heading "type" into "txt" variable when DOM is not yet completely loaded, also the heading value is undefined, better get the heading text by its innerHTML instead. Also there was no code to update "txt" variable when we change heading "type" text. That way "txt" variable will only contain the initial text of heading "type". I have modified the JS code a bit, try and see if this works for you : ). var i; var txt; var speed = 150; function updateText() { txt = document.getElementById("type").innerHTML; i = 0; document.getElementById("demo").innerHTML = ""; } window.onload = function() { updateText(); var demo = document.getElementById("type"); demo.addEventListener("input", updateText); } function triter() { if (i < txt.length) { document.getElementById("demo").innerHTML += txt.charAt(i); i++; setTimeout(triter, speed); } } Hth, cmiiw
23rd Nov 2018, 12:42 PM
Ipang
+ 5
You're welcome : )
23rd Nov 2018, 1:06 PM
Ipang
+ 3
thanks
23rd Nov 2018, 1:04 PM
B.D
B.D - avatar
+ 1
what your program must to do?
23rd Nov 2018, 9:01 AM
_yaroslavv [online_everyday]
_yaroslavv [online_everyday] - avatar