/exc.js-promises-typewriter

A simple JavaScript application that I developed while learning JS promises.

Primary LanguageJavaScriptCreative Commons Zero v1.0 UniversalCC0-1.0

JavaScript Typewriter with Promises

A simple JavaScript application, that I was create while I was learning JavaScript promises.

The initial task: Simple Joke Apps.

The current implementation provides much more functionalities, including: 1) Typewriter effect with sound; 2) DOM element to image implementation; 3) Session records of the fetched jokes; 4) Local storage for the user preferences; 5) Dynamic fetch of all resources; 6) Auto play feature; and more.

There are two variants of the main.js file. The only difference is within the main Joke.prototype.jokeType() method:

  • main-one-speed-param.js has a single parameter for a single character write time (speed) - it uses the following code to loop over the text.

    [...text].forEach((char, index, array) => {
        setTimeout(() => { typeSingleCharacter(char, index, array) }, index * speed);
    });
  • main-two-speed-params.js has two parameters for a single character write time (speed), one for the character write itself and one for a delay after that - it uses the code below to loop over the text, respectively the function typeSingleCharacter() is modified to work with promises.

    for (const index in text) {
        await typeSingleCharacter(text[index], index, text);
    }

Additional references: