Here is a simple implementation of the case where you want to verify input code.
In the above implementation anyone can call the method verifycode. Not good. Here is one way to fix this problem.
Another way to solve the same problem would be to create a constructor function. Here is an implementation.
Here is another way to solve the same problem. In this case I have moved all the public methods to prototype.