Im creating a function to make text a rainbow color.
I have two arrays. One for color and one for a string.
What I'm basically trying to do is loop over the colors as many times needed depending on how much text there are.
var colors = ['blue', 'red', 'green', 'black', 'orange', 'purple'];
function colorText(word) {
var slicedText = word.split('');
var rainbowText= '';
if (typeof(word) !== 'string') {
alert('Thats not a word!');
} else {
for (var i = 0; i < slicedText.length; i++ ) {
rainbowText += '<span style="color:' + colors[i] + ';">' + slicedText[i] + '</span>';
}
document.getElementById('text-input').innerHTML = rainbowText;
}
}
colorText('this is a really long text');
<div id="text-input">
</div>