Thermostat in javascript