forked from gSchool/stoplight-event-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (44 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function() {
'use strict';
function addMouseEnteredAndExit(element)
{
element.addEventListener('mouseenter',()=> {
console.log(`Entered ${element.innerText} button`);
})
element.addEventListener('mouseleave',()=>{
console.log(`Exited ${element.innerText} button`);
})
}
// YOUR CODE HERE
let stopButton = document.getElementById('stopButton');
let slowButton = document.getElementById('slowButton');
let goButton = document.getElementById('goButton');
stopButton.addEventListener('click', ()=>{
let stopLight = document.getElementById('stopLight');
stopLight.classList.toggle('stop');
if (stopLight.classList.contains('stop'))
console.log('stopLight bulb On');
else
console.log('stopLight bulb off')
});
slowButton.addEventListener('click', ()=>{
let slowLight = document.getElementById('slowLight');
slowLight.classList.toggle('slow');
if (slowLight.classList.contains('slow'))
console.log('slowLight bulb On');
else
console.log('slowLight bulb off');
})
goButton.addEventListener('click', ()=>{
let goLight = document.getElementById('goLight');
goLight.classList.toggle('go');
if (goLight.classList.contains('slow'))
console.log('slowLight bulb On');
else
console.log('slowLight bulb off');
})
document.body.
addMouseEnteredAndExit(stopButton);
addMouseEnteredAndExit(slowButton);
addMouseEnteredAndExit(goButton);
})();