I want to know what's wrong with my coding

OP, now, as a lesson, see if you can comment the code, so we know that you understand why it’s written that way…!