in reply to why dosn't my code work?

I know it's been mostly said already, but, may I suggest you check the FAQ on submitting questions?

How do I post a question effectively?

You've got the code there, and that's nice, but, as the FAQ I linked to says, "State exactly what the problem is. Be precise about the correct behavior / desired output."

I'm just sayin'.