Skip to content

Instantly share code, notes, and snippets.

@shtakai
Forked from anonymous/main.js
Created June 5, 2016 03:35
Show Gist options
  • Save shtakai/7f1155be237aa326ec1e3d0ea55bbc77 to your computer and use it in GitHub Desktop.
Save shtakai/7f1155be237aa326ec1e3d0ea55bbc77 to your computer and use it in GitHub Desktop.
var words = ["fun", "exciting", "about not giving up", "being helpful", "being open", "what I learned at CodingDojo!"],
el = document.getElementById('magic'),
word_counter = 0,
character_counter = 0;
function updateText()
{
var next_character = words[word_counter][character_counter++];
if(next_character == ' '){
next_character = ' ';
}
el.innerHTML = el.innerHTML+next_character;
if(character_counter == words[word_counter].length + 1)
{
word_counter++; //choose a different word
character_counter = 0; //start over with the first character of the word
el.innerHTML = ''; //set the html to be blank
//if we're displaying the last word, go back to the first word
if(word_counter == words.length)
word_counter = 0;
}
}
setInterval(updateText,250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment