diff --git a/index.html b/index.html index 53b6a34..8e8d073 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,13 @@ - + -

Lightbulb Selectors

-

You've clicked the lights 0 times

+

Lightbulb Selectors

+

You've clicked the lights 0 times

💡
@@ -16,7 +16,6 @@

You've clicked the lights 0 times

- - - \ No newline at end of file + + diff --git a/script.js b/script.js index 7056c69..4328af3 100644 --- a/script.js +++ b/script.js @@ -1 +1,47 @@ -// Write your code here \ No newline at end of file +// 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"); +// }); diff --git a/style.css b/style.css index 4ee6777..461fca2 100644 --- a/style.css +++ b/style.css @@ -31,6 +31,7 @@ body { padding: 10px; margin: 20px; transition: 0.2s; + cursor: pointer; } .lightbulb {