Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<h1 class = "title">Lightbulb Selectors</h1>
<h3 class = "subtitle">You've clicked the lights 0 times</h3>
<h1 class="title">Lightbulb Selectors</h1>
<h3 class="subtitle">You've clicked the lights 0 times</h3>
<div id="wrapper">
<div class="row">
<div id="lightbulb1" class="item lightbulb active">💡</div>
Expand All @@ -16,7 +16,6 @@ <h3 class = "subtitle">You've clicked the lights 0 times</h3>
</div>
</div>
<!--Connect your script here-->


</body>
</html>
<script src="script.js"></script>
</html>
48 changes: 47 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
// Write your code here
// const bulb1 = document.getElementById("lightbulb1");
// const bulb2 = document.getElementById("lightbulb2");
// const bulb3 = document.getElementById("lightbulb3");
const bulbs = document.querySelectorAll(".item")
const counter = document.querySelector(".subtitle");
let count = 0;

bulbs.forEach((bulb) => {
bulb.addEventListener("click", function () {
count++;
if (count == 1) {
counter.innerHTML = `You've click the lights 1 time`;
} else {
counter.innerHTML = `You've click the lights ${count} times`;
}
bulb.classList.toggle("active");
})});

// bulb1.addEventListener("click", function () {
// count++;
// if (count == 1) {
// counter.innerHTML = `You've click the lights 1 time`;
// } else {
// counter.innerHTML = `You've click the lights ${count} times`;
// }
// bulb1.classList.toggle("active");
// });

// bulb2.addEventListener("click", function () {
// count++;
// if (count == 1) {
// counter.innerHTML = `You've click the lights 1 time`;
// } else {
// counter.innerHTML = `You've click the lights ${count} times`;
// }
// bulb2.classList.toggle("active");
// });

// bulb3.addEventListener("click", function () {
// count++;
// if (count == 1) {
// counter.innerHTML = `You've click the lights 1 time`;
// } else {
// counter.innerHTML = `You've click the lights ${count} times`;
// }
// bulb3.classList.toggle("active");
// });
1 change: 1 addition & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ body {
padding: 10px;
margin: 20px;
transition: 0.2s;
cursor: pointer;
}

.lightbulb {
Expand Down