Creating a User-defined Function in JavaScript