55 lines
2.2 KiB
Markdown
Raw Normal View History

2015-11-03 13:12:44 -07:00
# Stoplight Exercise
2016-11-11 06:39:50 -08:00
As always, fork and clone this repository.
2015-11-03 13:12:44 -07:00
2016-11-11 06:46:41 -08:00
![](stoplight.gif)
2015-11-03 13:12:44 -07:00
2016-11-11 06:29:57 -08:00
## Part 1
2016-05-12 10:47:40 -07:00
2016-11-11 07:07:44 -08:00
Add DOM event listeners and handlers to toggle the on/off state of three bulbs.
2016-05-12 09:08:39 -07:00
2016-11-11 07:42:24 -08:00
- When a user clicks on the "Stop" button, toggle the [stop bulb's color][stop-color].
- When a user clicks on the "Slow" button, toggle the [slow bulb's color][slow-color].
- When a user clicks on the "Go" button, toggle the [go bulb's color][go-color].
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
**TIP**: All three bulbs can be on/off independently of one another.
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
### Resources
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
- [MDN - `Document.querySelector()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
- [MDN - `EventTarget.addEventListener()`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
- [MDN - `click`](https://developer.mozilla.org/en-US/docs/Web/Events/click)
2016-11-11 07:42:24 -08:00
- [MDN - `Element.classList`](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList)
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
## Part 2
2016-05-12 09:08:39 -07:00
2016-11-11 07:07:44 -08:00
Add new DOM event listeners and handlers to log the mouse state of each button.
2016-05-12 09:08:39 -07:00
2016-11-11 06:40:56 -08:00
- When a user's mouse enters a button, log `"Entered <textContent> button"` to the console.
- When a user's mouse leaves a button, log `"Left <textContent> button"` to the console.
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
**TIP:** Each event type will need a separate event listener.
2016-05-12 09:08:39 -07:00
2016-11-11 06:29:57 -08:00
### Resources
2015-11-03 13:12:44 -07:00
2016-11-11 06:29:57 -08:00
- [MDN - `mouseenter`](https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter)
- [MDN - `mouseleave`](https://developer.mozilla.org/en-US/docs/Web/Events/mouseleave)
2016-11-11 06:43:35 -08:00
- [MDN - `Event.target`](https://developer.mozilla.org/en-US/docs/Web/API/Event/target)
2016-11-11 06:29:57 -08:00
## Bonus
2016-11-11 07:42:24 -08:00
Add **one** DOM event listener and **one** handler to log the state of each bulb.
2016-11-11 06:29:57 -08:00
- When a user clicks a button that just turned on, log`"<textContent> bulb on"` to the console.
- When a user clicks a button that just turned off, log`"<textContent> bulb off"` to the console.
**TIP:** A click on only a button should cause a message to be logged to the console.
2016-05-12 10:53:37 -07:00
2016-11-11 06:29:57 -08:00
### Resources
2015-11-03 13:12:44 -07:00
2016-11-11 06:29:57 -08:00
- [How JavaScript Event Delegation Works](https://davidwalsh.name/event-delegate)
2016-11-11 07:42:24 -08:00
2016-11-11 08:06:39 -08:00
[stop-color]: https://github.com/gSchool/stoplight-event-exercise/blob/master/index.css#L39
[slow-color]: https://github.com/gSchool/stoplight-event-exercise/blob/master/index.css#L43
[go-color]: https://github.com/gSchool/stoplight-event-exercise/blob/master/index.css#L47