Writing the JavaScript client code