Compare commits

..

32 Commits

Author SHA1 Message Date
Ryan Sobol
42cd4def25 Improve the solution 2016-11-11 10:18:36 -08:00
Ryan Sobol
43488eeaea Improve the solution 2016-11-11 10:17:14 -08:00
Ryan Sobol
0336132c61 Flex 2016-11-11 08:07:19 -08:00
Ryan Sobol
4f58ad1fe5 Improve the README 2016-11-11 07:41:02 -08:00
Ryan Sobol
eb209062e2 Improve the solution 2016-11-11 07:39:19 -08:00
Ryan Sobol
71e29f11e0 Improve the README 2016-11-11 07:07:37 -08:00
Ryan Sobol
4764a09973 Improve the README 2016-11-11 07:04:45 -08:00
Ryan Sobol
309de303d0 Improve the gif 2016-11-11 07:01:03 -08:00
Ryan Sobol
50ad6cc1c5 Improve the solution 2016-11-11 06:54:27 -08:00
Ryan Sobol
2ac097d1ac Improve the solution 2016-11-11 06:53:23 -08:00
Ryan Sobol
ba764541e2 Improve the solution 2016-11-11 06:52:25 -08:00
Ryan Sobol
f6a2117f78 Improve the README 2016-11-11 06:48:25 -08:00
Ryan Sobol
c6c2d8603f Improve the README 2016-11-11 06:47:52 -08:00
Ryan Sobol
030b3dad90 Improve the README 2016-11-11 06:43:47 -08:00
Ryan Sobol
a66d9832f6 Improve the README 2016-11-11 06:41:09 -08:00
Ryan Sobol
725a770a94 Improve the README 2016-11-11 06:39:43 -08:00
Ryan Sobol
69ab2f12d0 Remove screenshot 2016-11-11 06:35:22 -08:00
Ryan Sobol
7098962ce3 Improve the README 2016-11-11 06:34:56 -08:00
Ryan Sobol
12ccebe93c Improve the README 2016-11-11 06:34:32 -08:00
Ryan Sobol
a0c30c23ad Improve the README 2016-11-11 06:28:18 -08:00
Ryan Sobol
e1e7877f94 Improve the README 2016-11-11 06:20:01 -08:00
Ryan Sobol
34474839ec Improve the README 2016-11-11 06:17:23 -08:00
Ryan Sobol
25674b5ce6 Improve the README 2016-11-11 06:16:49 -08:00
Ryan Sobol
36ebf6f0b4 Improve the README 2016-11-11 06:16:15 -08:00
Ryan Sobol
8cfc31392b Improve the README 2016-11-11 06:15:22 -08:00
Ryan Sobol
480f94030e Rename 2016-11-11 05:51:17 -08:00
Ryan Sobol
a5bc7aa76c Tweak CSS 2016-11-11 05:50:16 -08:00
Ryan Sobol
d489b8e893 Tweak HTML 2016-11-11 05:49:47 -08:00
Ryan Sobol
eec0a7ed3d Improve solution 2016-11-11 05:44:34 -08:00
Ian Smith
549e267eea updated readme and created bonus 2016-05-12 09:01:39 -07:00
Ian Smith
a68eb6a985 updated exercise 2016-05-11 22:33:20 -07:00
Danny Fritz
a3fcfe763f :neckbeard: Danny's solution 2015-11-03 13:21:50 -07:00

103
index.js
View File

@ -1,23 +1,80 @@
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<buttons.length;i++) {
buttons[i].addEventListener("mouseenter",(e)=>{
console.log("Entered "+e.target.innerHTML+" button.")
})
buttons[i].addEventListener("mouseleave",(e)=>{
console.log("Left "+e.target.innerHTML+" button.")
})
}
})
(function() {
'use strict';
const stopButton = document.querySelector('#stopButton');
const slowButton = document.querySelector('#slowButton');
const goButton = document.querySelector('#goButton');
const stopLight = document.querySelector('#stopLight');
const slowLight = document.querySelector('#slowLight');
const goLight = document.querySelector('#goLight');
// part 1
stopButton.addEventListener('click', () => {
stopLight.classList.toggle('stop');
// or...
// if (stopLight.classList.contains('stop')) {
// stopLight.classList.remove('stop');
// }
// else {
// stopLight.classList.add('stop');
// }
});
slowButton.addEventListener('click', () => {
slowLight.classList.toggle('slow');
});
goButton.addEventListener('click', () => {
goLight.classList.toggle('go');
});
// part 2
const handleMouseEnter = (event) => {
console.log(`Entered ${event.target.textContent} button`);
};
const handleMouseLeave = (event) => {
console.log(`Left ${event.target.textContent} button`);
};
stopButton.addEventListener('mouseenter', handleMouseEnter);
slowButton.addEventListener('mouseenter', handleMouseEnter);
goButton.addEventListener('mouseenter', handleMouseEnter);
stopButton.addEventListener('mouseleave', handleMouseLeave);
slowButton.addEventListener('mouseleave', handleMouseLeave);
goButton.addEventListener('mouseleave', handleMouseLeave);
// bonus
const controls = document.querySelector('#controls');
controls.addEventListener('click', (event) => {
if (event.target === controls) {
return;
}
let status;
if (event.target === stopButton) {
status = stopLight.classList.contains('stop') ? 'on' : 'off';
// or...
// if (stopLight.classList.contains('stop')) {
// status = 'on';
// }
// else {
// status = 'off';
// }
}
else if (event.target === slowButton) {
status = slowLight.classList.contains('slow') ? 'on' : 'off';
}
else {
status = goLight.classList.contains('go') ? 'on' : 'off';
}
console.log(`${event.target.textContent} bulb ${status}`);
});
})();