Every person who attempts to commit an offense against the ordinances of the town, and in such attempt does any act toward the commission of such offense, but fails or is prevented or intercepted in the perpetration thereof, is guilty of an offense, and shall be punished in the manner prescribed for the attempted offense itself.