Update app.js

Extracted getTemperature into a function.