I have been developing a script that when a user types in correctly entered text the images will change the letter, letting the user know they entered it in correctly.
Preview here: Example word is “ate”.
http://jsfiddle.net/wjx6b/2/
I made sure it was set to check the index by using
$.each(text, function(index, item)
My problem is when I try setting it to a foreign word like “taberu” which is Japanese, I have to have two letters in each of the var text boxes like this
var text = ['ta', 'be', 'ru'];
but when I set it to that nothing happens when I start to type. Thanks to anyone who can help!
The values in the ‘typed’ array are accessed one by one, while in the text array you put the characters in pairs as one value. So you’re comparing one character to a two character string in that case (comparing ‘ta’ to ‘t’, ‘be’ to ‘a’, ‘ru’ to ‘b’. Which will never be equal of course).
To account for that you have to take the ‘stepsize’ into account (that is, in how many characters the images are grouped). Using substring you can then compare typed text blocks of size ‘stepsize’ to the values from the text array.
working fiddle (you have to type aattee instead of ate now)
another fiddle, here you have to type ‘taberu’
in this fiddle stepsize is based on the first item of the text array
this fiddle dynamically detects the stepsize in case the values in the text array do not have the same length (thanks to haynar for the suggestion)
Update: this is the code of the last example (thanks Bob):