Skip to content

Instantly share code, notes, and snippets.

@alexparker
Last active October 7, 2015 10:37
Show Gist options
  • Select an option

  • Save alexparker/3151890 to your computer and use it in GitHub Desktop.

Select an option

Save alexparker/3151890 to your computer and use it in GitHub Desktop.
Javascript exercises
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);
@alexparker
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment