Skip to content

Commit c72c932

Browse files
committed
Added javascript in a seperate file
1 parent 8510369 commit c72c932

File tree

3 files changed

+52
-56
lines changed

3 files changed

+52
-56
lines changed

JAVASCRIPT BUTTON APP/index.html

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,62 +27,7 @@ <h2 id="change-my-color">Challenge 4: Changing the colors of all buttons</h2>
2727
</div>
2828

2929
</div>
30-
31-
<script>
32-
function buttonChangeColor(buttonThingy) {
33-
console.log(buttonThingy.value);
34-
35-
if(buttonThingy.value === "red") {
36-
buttonRed();
37-
} else if(buttonThingy.value === "green") {
38-
buttonGreen();
39-
} else if(buttonThingy.value === "reset") {
40-
buttonReset();
41-
} else {
42-
buttonRandom();
43-
}
44-
}
45-
46-
let all_buttons = document.getElementsByTagName("button");
47-
48-
var copy_all_buttons = [];
49-
for (let i = 0; i< all_buttons.length; i++) {
50-
copy_all_buttons.push(all_buttons[i].classList[1]);
51-
console.log(copy_all_buttons);
52-
}
53-
54-
function buttonRed() {
55-
for (let i = 0; i< all_buttons.length; i++) {
56-
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
57-
all_buttons[i].classList.add("btn-red");
58-
}
59-
}
60-
61-
function buttonGreen() {
62-
for (let i = 0; i< all_buttons.length; i++) {
63-
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
64-
all_buttons[i].classList.add("btn-green");
65-
}
66-
}
67-
68-
function buttonReset() {
69-
for (let i = 0; i< all_buttons.length; i++) {
70-
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
71-
all_buttons[i].classList.add(copy_all_buttons[i]);
72-
}
73-
}
74-
75-
function buttonRandom() {
76-
let choices = ["btn-red", "btn-green", "btn-yellow", "btn-blue"];
77-
for (let i = 0; i< all_buttons.length; i++) {
78-
let random = Math.floor(Math.random() * 4);
79-
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
80-
all_buttons[i].classList.add(choices[random]);
81-
}
82-
}
83-
84-
85-
</script>
30+
<script src="js/script.js"></script>
8631

8732
</body>
8833

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function buttonChangeColor(buttonThingy) {
2+
console.log(buttonThingy.value);
3+
4+
if(buttonThingy.value === "red") {
5+
buttonRed();
6+
} else if(buttonThingy.value === "green") {
7+
buttonGreen();
8+
} else if(buttonThingy.value === "reset") {
9+
buttonReset();
10+
} else {
11+
buttonRandom();
12+
}
13+
}
14+
15+
let all_buttons = document.getElementsByTagName("button");
16+
17+
var copy_all_buttons = [];
18+
for (let i = 0; i< all_buttons.length; i++) {
19+
copy_all_buttons.push(all_buttons[i].classList[1]);
20+
console.log(copy_all_buttons);
21+
}
22+
23+
function buttonRed() {
24+
for (let i = 0; i< all_buttons.length; i++) {
25+
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
26+
all_buttons[i].classList.add("btn-red");
27+
}
28+
}
29+
30+
function buttonGreen() {
31+
for (let i = 0; i< all_buttons.length; i++) {
32+
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
33+
all_buttons[i].classList.add("btn-green");
34+
}
35+
}
36+
37+
function buttonReset() {
38+
for (let i = 0; i< all_buttons.length; i++) {
39+
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
40+
all_buttons[i].classList.add(copy_all_buttons[i]);
41+
}
42+
}
43+
44+
function buttonRandom() {
45+
let choices = ["btn-red", "btn-green", "btn-yellow", "btn-blue"];
46+
for (let i = 0; i< all_buttons.length; i++) {
47+
let random = Math.floor(Math.random() * 4);
48+
all_buttons[i].classList.remove(all_buttons[i].classList[1]);
49+
all_buttons[i].classList.add(choices[random]);
50+
}
51+
}

JAVASCRIPT BUTTON APP/script.js

Whitespace-only changes.

0 commit comments

Comments
 (0)