I need help to conceptually understand how to compare the following case:
Paragraph is given: “Hello Ladies and gentlemen, welcome to my example” .
User has to write the same sentence through input bar.
The first word the user types counts until user presses “Spacebar”.
Meaning, if user types Hellooooowe and hits space, the whole words is compared to the first word of the paragraph, i.e “Hello”.
Same for the rest, doesn’t matter how long the words is, it’s still compared to the next of order from pargarph.
To store both the given text and user’s values in two arrays.
Whenever user press Space, the word he typed is added to array and compared with the text’s array. like
userArray === textArray.
There is something I can’t understand though,
whenever user hits “backspace” - he can edit the previous word. how?
Copy & Splice the last word from array?
and if user deletes the word as well, he can access the word before that as well.
And when the word does not match, what do you want to happen? An alert pop up or something? Like @camelcamper asked, what is the ultimate purpose what you want to do? Are you just trying to make sure as a user types in the input box, that the text typed matches up to that point in the paragraph? If so, then after every key stroke in the text box just compare the input’s value to a slice of the paragraph up to the same number of characters currently in the input.
I built a simple typing game with React that evaluates user’s WPM( Words Per Minute), and to make it more accurate I’d like to see when a user types a word and the word doesn’t match the on from the paragraph.
Additionally I want the user to be able to go back (backspace) and fix/edit what he wrote.