Calculating score problem

I downloaded a Cross Word game from and I modified it a little bit to suit my needs which is to display “you passed” or “you failed” and calculate the right score result once the user complete the game and press on the show answers button.

Well the problem is that when I completed the game, it sometimes give me this wrong score calculation and different message. For instance, when I complete the game perfectly correct it suppose to show 12 for the score but it doesn’t.

I’ve spent so much time trying to fix it. Hope to get help soon.

you can get the source code from this link