forked from gSchool/stoplight-event-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (75 loc) · 3.63 KB
/
Copy pathscript.js
File metadata and controls
90 lines (75 loc) · 3.63 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Write JS to make this stoplight work.
When I click on the 'stop' button,
the top light should turn red.
When I click on the 'slow' button
the middle light should turn orange.
When I click on the 'go' button
the bottom light should turn green.
*/
// document.getElementById('stopButton').addEventListener(mouseover, function(){
// alert(document.getElementById('stopButton').textContent)
// })
document.getElementById('stopButton').addEventListener('mouseover', function(){
console.log('Entered ' + document.getElementById('stopButton').textContent + ' button')
})
document.getElementById('slowButton').addEventListener('mouseover', function(){
console.log('Entered ' + document.getElementById('slowButton').textContent + ' button')
})
document.getElementById('goButton').addEventListener('mouseover', function(){
console.log('Entered ' + document.getElementById('goButton').textContent + ' button')
})
document.getElementById('stopButton').addEventListener('mouseleave', function(){
console.log('Left ' + document.getElementById('stopButton').textContent + ' button')
})
document.getElementById('slowButton').addEventListener('mouseleave', function(){
console.log('Left ' + document.getElementById('slowButton').textContent + ' button')
})
document.getElementById('goButton').addEventListener('mouseleave', function(){
console.log('Left ' + document.getElementById('goButton').textContent + ' button')
})
document.getElementById('controls').addEventListener('click', function(){
console.log(event.target.textContent);
})
document.getElementById('stopButton').addEventListener('click', function() {
if (document.getElementById('stopLight').style.backgroundColor === 'red') {
document.getElementById('stopLight').style.backgroundColor = 'black';
} else {
document.getElementById('stopLight').style.backgroundColor = 'red';
}
})
document.getElementById('slowButton').addEventListener('click', function() {
if (document.getElementById('slowLight').style.backgroundColor === 'orange') {
document.getElementById('slowLight').style.backgroundColor = 'black';
} else {
document.getElementById('slowLight').style.backgroundColor = 'orange';
}
})
document.getElementById('goButton').addEventListener('click', function() {
if (document.getElementById('goLight').style.backgroundColor === 'green') {
document.getElementById('goLight').style.backgroundColor = 'black';
} else {
document.getElementById('goLight').style.backgroundColor = 'green';
}
})
document.getElementById('stopButton').addEventListener('click', function() {
if(document.getElementById('slowLight').style.backgroundColor === 'orange') {
document.getElementById('slowLight').style.backgroundColor = 'black';
} else if (document.getElementById('goLight').style.backgroundColor === 'green'){
document.getElementById('goLight').style.backgroundColor = 'black';
}
})
document.getElementById('slowButton').addEventListener('click', function() {
if(document.getElementById('stopLight').style.backgroundColor === 'red') {
document.getElementById('stopLight').style.backgroundColor = 'black';
} else if (document.getElementById('goLight').style.backgroundColor === 'green'){
document.getElementById('goLight').style.backgroundColor = 'black';
}
})
document.getElementById('goButton').addEventListener('click', function() {
if(document.getElementById('slowLight').style.backgroundColor === 'orange') {
document.getElementById('slowLight').style.backgroundColor = 'black';
} else if (document.getElementById('stopLight').style.backgroundColor === 'red'){
document.getElementById('stopLight').style.backgroundColor = 'black';
}
})