Last active
October 7, 2015 10:37
-
-
Save alexparker/3151890 to your computer and use it in GitHub Desktop.
Javascript exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var xi = 0; | |
| var evnt = jQuery.Event('keyup'); | |
| evnt.keyCode = evnt.which = 32; | |
| function enterWord(){ | |
| $('input#inputfield').val($('.highlight').text()); | |
| $('input#inputfield').trigger(evnt); | |
| } | |
| var wpm = prompt("How many words per minute would you like?"); | |
| var ms = 60000/parseInt(wpm,10); | |
| var int = setInterval("enterWord()", ms); | |
| var timer = setInterval("xi++;if(xi==60 || !$('.highlight').length){clearInterval(int);clearInterval(timer);}", 1000); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I was doin a little exercise, and wrote a little hack for a certain (unnamed) typing test website just to see if i could, and how i might go about it. This is what I ended up with.
The way the timer interval gets cleared is a little weird. I'm wondering if there is a better way to do this? Just looking to improve my coding methods and perspective.
Functionality-wise, the way the interface of the site works is this:
There is a reference box with 2 lines of words that you are to type, but you enter the words into a text field, one word at a time. When you enter the word then hit space, the space keyup event is what clears the text-field and moves the focused or highlighted word in the reference box to the next word. When you enter the last word on the first line, the first line disappears, the second line becomes the first and a new line shows up below it (basically just scrolls)