Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,50 @@

<script>

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()
// wrap variable definitions in immediate function
(function()
{
el.innerHTML = el.innerHTML+words[word_counter][character_counter++];
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;

if(character_counter == words[word_counter].length)
function updateText()
{
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 a space is encountered, add a blank space and increment counter
if(words[word_counter][character_counter] == ' ')
{
el.innerHTML += '&nbsp;';

character_counter++;
}
else
{
// else, preceed as usual
el.innerHTML = el.innerHTML+words[word_counter][character_counter++];
}

// added 1 to length so we don't switch words before displaying final character in phrase
if(character_counter == words[word_counter].length + 1)
{
// choose a different word
word_counter++;
// start over with the first character of the word
character_counter = 0;
// set the html to be blank
el.innerHTML = '';

//if we're displaying the last word, go back to the first word
if(word_counter == words.length)
word_counter = 0;
// if we're displaying the last word, go back to the first word
if(word_counter == words.length)
word_counter = 0;
}
}
}

setInterval(updateText,300);
setInterval(updateText,300);

}());


</script>

</body>
Expand Down