I'm sorry, but there's just some very bad logic in that code.
There are no coding errors, per se (that is, no errors show up in the error console), but the logic of the game just makes no sense.
In addition, the user interface and the game play isn't very good.
I would go find a different version with better code. That code just isn't worth trying to fix, in my opinion.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.