-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.js
146 lines (101 loc) · 3.12 KB
/
1.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
const color = ["red","blue","yellow","green"];
let shuffledColors = [];
let turn = 0;
function playCorrectSound() {
let correct = new Audio("sounds/cute-level-up-3-189853.mp3");
correct.play();
}
function showColors(){
return color.sort(()=> Math.random() -5.0);
}
function displayAndFadeColors(){
shuffledColors= showColors();
console.log(shuffledColors);
for ( let i= 0; i< shuffledColors.length; i++) {
console.log( shuffledColors[i])
let squareEL = document.querySelector(`#${shuffledColors[i]}`);
setTimeout (() => {
squareEL.style.backgroundColor =shuffledColors[i];
}, i * 1000);
setTimeout(()=>{
squareEL.style.backgroundColor="white";
}, i * 1000 + 1000);
}
}
function checkColors(turn, clickedColor) {
if (clickedColor === shuffledColors[turn]) {
if (turn === shuffledColors.length - 1) {
playCorrectSound();
alert("You won ");
setTimeout(() => {}, 3000);
}
} else {
alert("You lost ");
displayAndFadeColors();
}
}
function makeAllColorsWhite() {
const squares = document.querySelectorAll(".red, .blue, .yellow, .green");
for (let i = 0; i < squares.length; i++) {
squares[i].style.backgroundColor = "white";
}
}
const colorRedEL = document.querySelector("#red");
const colorBlueEL = document.querySelector("#blue");
const coloryellowEL = document.querySelector("#yellow");
const colorGreenEL = document.querySelector("#green");
const buttonStartEL = document.querySelector("#button_start");
colorRedEL.addEventListener("click", () =>{
checkColors(turn, "red");
turn++;
});
colorBlueEL.addEventListener("click", () => {
checkColors(turn, "blue");
turn++;
});
coloryellowEL.addEventListener("click", () => {
checkColors(turn, "yellow");
turn++;
});
colorGreenEL.addEventListener("click", () =>{
checkColors(turn, "green");
turn++;
});
buttonStartEL.addEventListener("click", () => { displayAndFadeColors();
});
/*
function makeAllTheColorWhite(){
const squares= document.querySelectorAll(".red, .blue, .yellow, .green");
for (let i =0; i< squares.length; i++){
console.log(squares[i]);
squares[i].style.backgroundColor="white"
}
}
/* */
/* colorRedEL.addEventListener("click", ()=>{
});
colorBlueEL.addEventListener("click", ()=>{
});
coloryellowEL.addEventListener("click", ()=>{
});
colorGreenEL.addEventListener("click", ()=>{
}); */
/* const element = document.getElementById("red","blue","yellow","green");
element.addEventListener("click", showTheAnswr2); */
/* const pickColor = ['green', 'yellow', 'blue', 'red'];
function showTheAnswr() {
if ( pickColor === pickColor) {
alert("winner!");
} else {
alert("try agine");
}
} */
/* const pickColor2 = ['red', 'blue', 'yellow', 'green']
function showTheAnswr2() {
const element = document.getElementById("red","blue","yellow","green");
if ( pickColor2 === pickColor2) {
("click", ()=>{ alert ("winner!")})
} else {
alert("try agine");
}
} */