Writing a thermostat program in JavaScript