My ‘AutoType’ function to type words automatically DOESN’T WORK

Details

Its a simple code. It gets the words in all .auto-type elements as input, then
type them automatically.

Here’s the CodePen : https://codepen.io/akolad/pen/zYPoEWd

Codes

  • javascript
    window.onload = () => {
        let elements = document.getElementsByClassName("auto-type");
        for (element of elements) {
            const text = element.innerHTML.toString();
            let charIndex = 0;
            const typing = () => {
                element.innerHTML += text.charAt(charIndex);
                if (charIndex < text.length) {
                    setTimeout(typing, 100);
                    charIndex++;
                }
            };
        }
    };
    
  • html (body)
    <body>
        <span class="auto-type code">hello!</span>
        <br />
        <span class="auto-type code">some text</span>
        <br />
        <div class="auto-type">some other text</div>
        <span class="auto-type code">here is a better text</span>
    
        <!-- js file: -->
        <script type="text/javascript" src="AutoType.js"></script>
    </body>
    

Problem

actually, js codes doesn’t work. and console is empty(no errors).
where’s the problem?