change the code in app.js to a function