Hello, i am making a keyboarding site for my class, and i have a div with some text inside, when they type, i want to check if the text matches the text in the div, if it dosn't, i wan't to update a box with an "error count". How can i achive this?

Recommended Answers

All 8 Replies

Compare strings - true/false - easy.

Error count - unknown paradigm - difficult.

Member Avatar for stbuchok

for error count you could just simply loop through each character and compare to make sure they match. This has a problem though, if, for instance, the person types an extra space but doesn't correct for it, every character after the space will be wrong.

Exactly. Same happens for any omission or extra character. It's not a fair measure of fidelity as it penalises an early error far more than a late error.

I wonder if John Resig's Javascript Diff Algorithm might offer a way ahead? It won't give an error count but instead will generate a version of the typed string, highlighted on a word-by-word basis to indicate its differnece from the original. That's the best I can come up with.

DEMO

Hello, i am making a keyboarding site for my class, and i have a div with some text inside, when they type, i want to check if the text matches the text in the div, if it dosn't, i wan't to update a box with an "error count". How can i achive this?

Is this a typing practice class?

commented: Yes this is for a class in my highschool. I am making it for my teacher +0
Member Avatar for stbuchok

Actually, it shouldn't be too hard to take that js file and have it output the number of errors as well. Good find Airshow.

Mmm, not so trivial Stb because the algorithm works on whole words rather than individual characters.

It helps to space-separate every character in the strings :

DEMO

But the behaviour is not perfect. Total errors should be the sum of "Errors" and "Omissions", however :

  • A single incorrect character results in an Error and and Omission.
  • It's hard to find a reliable way to suppress "omissions" for the as yet unattempted part of the text.
  • The algorithm isn't tollerant of gross errors; try typing "Pleeze retipe that."

So how exactly would i do this? I'm more used to coding with php/html/css. And i'm more learning java. And this is confusing me,

I wan't it to count the errors. And show them which character they should be typing at the momment, so like highlet, or underscore the character there currently typing

Oh and by the way sorry it took a while to respond, it hasn't been letting me log into daniweb :(

And finally:
are you interested in counting all the typing errors as you go, or only the errors reflected at the final output?

The answer to this question is very important since it shapes the backbone of the algorithm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.