Reworking the js code for the app using the object literal method in app2