in reply to Bad Code?

This looks good it works correctly. My only suggestion would be to get use to using strict. becuase when you start writing longer and more complicated programs they are easier to maintain and trouble shoot when you use strict since everything is localized