Keyon Keyon - 23 days ago 18
HTML Question

Typed.js random word

Is there a way to get a random word with Typed.js?

$(function(){
$(".element").typed({
strings: ["Lorem", "Ipsum", "Dolor"],
typeSpeed: 0
});
});


Output should be one of these words. (Lorem / Ipsum / Dolor)

Answer

You could use Math.Random() to select a random item in the array

like:

$(function(){
    var stringArray = ["Lorem", "Ipsum", "Dolor"];
    var randomNumber = Math.round(Math.random() * (stringArray.length - 1)); //random number between 0 and stringArray length
    $(".element").typed({
        strings: [stringArray[randomNumber]],
        typeSpeed: 0
    });
});
Comments