This code is plain wrong because you removed parts from Crazy programmer code. The problem is that everything matters.
Compare your code with original, you will see what is missing.
Quote:
I have debug the code
You don't know how to use debugger, because otherwise you would have seen the problem.
Debugger is a tool and you have to learn how to use it.
It looks like HomeWork, so only hints.