Building a Smart Home Automation System
Story
Welcome to the world of smart home automation! You've been hired by SmartHome Inc., a company that specializes in creating intelligent home automation systems. Your task is to develop a series of JavaScript functions that will help manage various devices and settings in a smart home.
Objectives
By the end of this exercise, students will be able to:
- Understand and use arrow functions.
- Implement and utilize callback functions.
- Work with default parameters in functions.
- Create and apply higher order functions.
Scenario
SmartHome Inc. wants to automate the following tasks:
Control the lights based on time of day. Adjust the thermostat based on the weather. Manage a list of devices and perform various operations on them.
Tasks
1. Control the Lights
Create a function controlLights
that takes the current hour as an argument and returns a message indicating whether the lights should be turned on or off. Use default parameters to set the default hour to the current hour.
2. Adjust the Thermostat
Create a function adjustThermostat
that takes the current temperature and a callback function. The callback function should determine whether to turn the heating or cooling on or off. Use arrow functions for the callback.
3. Manage Devices
Create a higher order function manageDevices
that takes an array of device names and a callback function to perform operations on each device. The callback function should accept a device name and perform an operation, such as turning the device on or off.