Store the user input (from prompt, textbox, or any other input fields) to the variable.
Store the correct answer into another variable.
Convert the two variables into array consisting each word in a sentence. (As what peguerosdc said)
Make a loop that ends at the last index of the array of the inputted word. This loop let the two words from the inputted sentence and the correct sentence be compared and it shall make the color of the word to blue if it is matched and red for not.
Sample code:
for (int i=0; i<words.length;i++) // loop until the end of the word
{
if(word[i]==correctWord[i]) // compare the word from user input to the word of correct sentence
{
// color it blue
}
else
{
// color it red
}
}