Function To Set Random Colors To Each Letters In A Word.

function applyRandomColors(text) {
        var coloredText = '';

        for (var i = 0; i < text.length; i++) {
            var randomColor = 'rgb(' +
                Math.floor(Math.random() * 256) + ',' +
                Math.floor(Math.random() * 256) + ',' +
                Math.floor(Math.random() * 256) +
                ')';

            coloredText += '<span style="color: ' + randomColor + ';">' + text[i] + '</span>';
        }

        return coloredText;
    }

Leave a comment

Your email address will not be published. Required fields are marked *