From f57da84b34f0f6b8e6deb337955c3eed56f59a55 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Thu, 11 Jun 2020 10:45:08 +0900 Subject: [PATCH] Implement solution. --- index.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 03cc920..429f493 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,23 @@ -(function() { - 'use strict'; - - // YOUR CODE HERE -})(); +document.addEventListener("DOMContentLoaded",()=>{ + document.getElementById("controls").addEventListener("click",(clicked)=>{ + var lightPrefix = clicked.target.id.replace("Button",""); + var targetLight = document.getElementById(lightPrefix+"Light"); + if (!targetLight.classList.contains(lightPrefix)) { + targetLight.classList.add(lightPrefix); + console.log(lightPrefix+" bulb on.") + } else { + targetLight.classList.remove(lightPrefix); + console.log(lightPrefix+" bulb off.") + } + }) + + var buttons = document.getElementsByClassName("button"); + for (var i=0;i{ + console.log("Entered "+e.target.innerHTML+" button.") + }) + buttons[i].addEventListener("mouseleave",(e)=>{ + console.log("Left "+e.target.innerHTML+" button.") + }) + } +}) \ No newline at end of file