index.js 620 B

123456789101112131415161718
  1. var typeMessage = ( function ( velocity ) {
  2. let container = document.getElementById ( "demo" ) ?
  3. document.getElementById ( "demo" ) :
  4. document.body.appendChild (
  5. document.createElement ( "h3" )
  6. )
  7. container.style = `color: magenta;`
  8. var index = 0
  9. return function ( message ) {
  10. let timerId = setTimeout(function showMessage() {
  11. setTimeout(showMessage, velocity * 1000);
  12. index > message.length ? null : container.innerText = message.substring(0, index);
  13. index++;
  14. });
  15. }
  16. })( 1 )
  17. typeMessage ( `Welcome to the hell` )