in reply to why dosn't my code work?
As a general guide, when you ask the question "Why doesn't my code work" then you should define what "work" means. In other word, describe what you expect to happen.
Then try to describe what actually happened. The difference between the two gives a clue as to the problem. Often the act of writing down a description of the problem will give you the answer. Or at least make it easier for others to help.