-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
228 lines (196 loc) · 6.73 KB
/
script.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
console.log("It WORKS!"); //This tests if the script is working and linked to we page in js console
//This saves the h1 element in the "title" variable
const title = document.querySelector("#title");
const words = document.querySelector("#words")
//This displays what is saves in my "title" variable in the console
console.log(title);
//This adds the text "DOM PORJECT" to the "title" variable which is assigned an element in my html
title.innerHTML = title.innerHTML + " DOM Project";
//this function accessess the element with id of "today" in my html and changes it to the current date
function displayDate(){
document.getElementById("today").innerHTML = Date();
}
function restart(){
bulbOne.src = "orangeLightblub.PNG";
bulbTwo.src = "orangeLightblub.PNG";
bulbThree.src = "orangeLightblub.PNG";
bulbFour.src = "orangeLightblub.PNG";
state1 = 'o';
state2 = 'o';
state3 = 'o';
state4 = 'o';
turn = 1;
console.log("Restart");
}
//Variable for each lightbulb
var bulbOne = document.querySelector("#bulb1");
var bulbTwo = document.querySelector("#bulb2");
var bulbThree = document.querySelector("#bulb3");
var bulbFour = document.querySelector("#bulb4");
//Variable for states to check which state each lightbulb is in
var state1 = "o"
var state2 = "o"
var state3 = 'o'
var state4 = 'o'
//Variable for number of turn
var turn = 1;
/*
function winner(){
//winning algorithm
if(state1 =='p' && state2 =='p'&&state3 =='p'&& state4 =='p' ){
title.innerHTML = title.innerHTML("YOUR A WINNER!!")
}
} */
//Check each
console.log(bulbOne);
console.log(bulbTwo);
console.log(bulbThree);
console.log(bulbFour);
//console.log(state1)
//Event listeners for each
bulbOne.addEventListener(
'click', function(){
console.log("Click")
console.log(turn%2);
if(turn%2 != 0){
if(state1 == 'o'){
bulbOne.src = "purpleLightbulb.PNG";
state1 = 'pp';
turn++;
console.log(turn);
}
else if(state1=='pp' && turn%2 != 0) {
bulbOne.src = "pinkLightbulb.PNG"
turn++;
state1 = 'p';
if(state1 =='p' && state2 =='p'&& state3 =='p' && state4 =='p' ){
document.getElementById("title").innerHTML = "YOU WON!";
document.getElementById("words").innerHTML = "YOU WON!";
document.getElementById("words").style.fontSize = "500%";
}
}
}else if(turn%2==0){//If on an even turn restart
bulbOne.src = "orangeLightblub.PNG";
bulbTwo.src = "orangeLightblub.PNG";
bulbThree.src = "orangeLightblub.PNG";
bulbFour.src = "orangeLightblub.PNG";
state1 = 'o';
state2 = 'o';
state3 = 'o';
state4 = 'o';
turn = 1;
console.log("Restart");
console.log(state1);
console.log(turn);
}
}
)
bulbTwo.addEventListener(
'click', function(){
console.log("bulb clicked!");
if(turn%2 == 0){
if(state2 == 'o'){
bulbTwo.src = "purpleLightbulb.PNG";
state2 = 'pp';
turn++;
console.log(turn);
}
else if(state2=='pp' && turn%2 == 0) {
bulbTwo.src = "pinkLightbulb.PNG"
turn++;
state2 = 'p';
if(state1 =='p' && state2 =='p'&& state3 =='p' && state4 =='p' ){
document.getElementById("title").innerHTML = "YOU WON!";
document.getElementById("words").innerHTML = "YOU WON!";
document.getElementById("words").style.fontSize = "500%";
}
}
}else if(turn%2!=0){//If on an even turn restart
bulbOne.src = "orangeLightblub.PNG";
bulbTwo.src = "orangeLightblub.PNG";
bulbThree.src = "orangeLightblub.PNG";
bulbFour.src = "orangeLightblub.PNG";
state1 = 'o';
state2 = 'o';
state3 = 'o';
state4 = 'o';
turn = 1;
console.log("Restart");
console.log(state2);
console.log(turn);
}
}
)
bulbThree.addEventListener(
'click', function(){
console.log("bulb clicked!");
if(turn%2 != 0){
if(state3 == 'o'){
bulbThree.src = "purpleLightbulb.PNG";
state3 = 'pp';
turn++;
console.log(turn);
}
else if(state3=='pp' && turn%2 != 0) {
bulbThree.src = "pinkLightbulb.PNG"
turn++;
state3 = 'p';
if(state1 =='p' && state2 =='p'&& state3 =='p' && state4 =='p' ){
document.getElementById("title").innerHTML = "YOU WON!";
document.getElementById("words").innerHTML = "YOU WON!";
document.getElementById("words").style.fontSize = "500%";
}
}
}else if(turn%2==0){//If on an even turn restart
bulbOne.src = "orangeLightblub.PNG";
bulbTwo.src = "orangeLightblub.PNG";
bulbThree.src = "orangeLightblub.PNG";
bulbFour.src = "orangeLightblub.PNG";
state1 = 'o';
state2 = 'o';
state3 = 'o';
state4 = 'o';
turn = 1;
console.log("Restart");
console.log(state1);
console.log(turn);
}
}
)
bulbFour.addEventListener(
'click', function(){
console.log("bulb clicked!");
if(turn%2 == 0){
if(state4 == 'o'){
bulbFour.src = "purpleLightbulb.PNG";
state4 = 'pp';
turn++;
console.log(turn);
}
else if(state4=='pp' && turn%2 == 0) {
bulbFour.src = "pinkLightbulb.PNG"
turn++;
state4 = 'p';
if(state1 =='p' && state2 =='p'&& state3 =='p' && state4 =='p' ){
document.getElementById("title").innerHTML = "YOU WON!";
document.getElementById("words").innerHTML = "YOU WON!";
document.getElementById("words").style.fontSize = "500%";
}
}
}else if(turn%2!=0){//If on an even turn restart
bulbOne.src = "orangeLightblub.PNG";
bulbTwo.src = "orangeLightblub.PNG";
bulbThree.src = "orangeLightblub.PNG";
bulbFour.src = "orangeLightblub.PNG";
state1 = 'o';
state2 = 'o';
state3 = 'o';
state4 = 'o';
turn = 1;
console.log("Restart");
console.log(state4);
console.log(turn);
}
}
)
//console.log(state1);