"Nailed it" means to have successfully completed something. A hammer is a tool used to push nails into an object such as a piece of wood. Nails are short, thin pieces of metal with a sharp end that are used to keep structures together. If something is "nailed" it means that something has had a nail driven into or through it. The joke is centered on the word "nailed" and its different meanings.
I didn ' t know which hammer to get , but I think I nailed it .