Button 7
Button 7
DOCTYPE html>
<html>
<head>
<title>Smart Home Control</title>
<style>
body {
background-color: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
.control-panel {
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
border-radius: 10px;
text-align: center;
}
.device {
margin-bottom: 20px;
}
.status {
width: 20px;
height: 20px;
border-radius: 50%;
display: inline-block;
margin-left: 10px;
}
.on {
background-color: yellow;
}
.off {
background-color: grey;
}
button {
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<div class="control-panel">
<div class="device">
<h2>Light</h2>
<div class="status" id="light-status"></div>
<br>
<button onclick="toggleDevice('light', 'on')">Turn On</button>
<button onclick="toggleDevice('light', 'off')">Turn Off</button>
</div>
<div class="device">
<h2>Fan</h2>
<div class="status" id="fan-status"></div>
<br>
<button onclick="toggleDevice('fan', 'on')">Turn On</button>
<button onclick="toggleDevice('fan', 'off')">Turn Off</button>
</div>
<div class="device">
<h2>Thermostat</h2>
<div class="status" id="thermostat-status"></div>
<br>
<button onclick="toggleDevice('thermostat', 'on')">Turn On</button>
<button onclick="toggleDevice('thermostat', 'off')">Turn Off</button>
</div>
<div class="device">
<h2>AC</h2>
<div class="status" id="ac-status"></div>
<br>
<button onclick="toggleDevice('ac', 'on')">Turn On</button>
<button onclick="toggleDevice('ac', 'off')">Turn Off</button>
</div>
</div>
<script>
function toggleDevice(device, state) {
const statusElement = document.getElementById(`${device}-status`);
if (state === 'on') {
statusElement.classList.add('on');
statusElement.classList.remove('off');
} else {
statusElement.classList.add('off');
statusElement.classList.remove('on');
}
}
</script>
</body>
</html>