-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.js
213 lines (181 loc) · 6.55 KB
/
first.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
function classSwap() {
var headings = document.getElementById("headingsDiv").children;
var userHeadingsSelect;
alert('There are ' + headings.length + ' elements.');
userHeadingsSelect = prompt("Which heading would you like to switch?");
headings[userHeadingsSelect].classList.toggle("headings");
}
function showHideDiv() {
var div = document.getElementById('headingsDiv');
if(div.style.display == "none"){
div.style.display = "block";
} else {
div.style.display = "none";
}
}
function showLess() {
var heading1 = document.getElementById("heading1");
var heading2 = document.getElementById("heading2");
var heading3 = document.getElementById("heading3");
var heading4 = document.getElementById("heading4");
var heading5 = document.getElementById("heading5");
var showMoreButton = document.getElementById('showMoreButton');
var showLessButton = document.getElementById("showLessButton");
if(heading5.style.display != "none"){
heading5.style.display = "none";
} else if(heading4.style.display != "none") {
heading4.style.display = "none";
} else if(heading3.style.display != "none") {
heading3.style.display = "none";
} else if(heading2.style.display != "none") {
heading2.style.display = "none";
} else if(heading1.style.display != "none") {
heading1.style.display = "none";
showLessButton.style.display = "none";
showMoreButton.style.display = "block";
}
}
function showMore() {
var heading1 = document.getElementById("heading1");
var heading2 = document.getElementById("heading2");
var heading3 = document.getElementById("heading3");
var heading4 = document.getElementById("heading4");
var heading5 = document.getElementById("heading5");
var showMoreButton = document.getElementById("showMoreButton");
var showLessButton = document.getElementById('showLessButton');
if(heading1.style.display == "none") {
heading1.style.display = "block";
} else if(heading2.style.display == "none") {
heading2.style.display = "block";
} else if(heading3.style.display == "none"){
heading3.style.display = "block";
} else if(heading4.style.display == "none") {
heading4.style.display = "block";
} else if(heading5.style.display == "none") {
heading5.style.display = "block";
showMoreButton.style.display = "none";
showLessButton.style.display = "block";
}
}
function eventListenerAdd() {
var x = document.getElementById('eventHandlerButton');
x.addEventListener('click', basicAlert);
x.textContent = "I have an event Now!";
}
function basicAlert() {
alert("Hello!");
}
window.onload = function() {
var heading = document.createElement("HEADING1");
var headingDiv = document.getElementById('headingsDiv');
heading.innerHTML = "This was Created on Page Load";
headingDiv.appendChild(heading);
}
document.onkeydown = function(e) {
var x = document.getElementById('sizeTestParagraph');
switch (e.key) {
case "ArrowUp":
x.style.fontSize = "larger";
break;
case "ArrowDown":
x.style.fontSize = "smaller";
break;
}
};
function mouseOverColor() {
document.getElementById('mouseOverText').style.backgroundColor = "teal";
}
function alterTextSizeAndColor() {
var x = document.getElementById('alterSizeColorText');
var userFontSize = parseInt(prompt("Give an Integer for the font size")) + "px";
var userColorChoice = prompt("Should I be Red or Blue?");
x.style.fontSize = userFontSize;
x.style.color = userColorChoice;
}
function fadeImg() {
var img = document.getElementById('babyYoda');
if(img.classList.contains('fade')){
img.setAttribute('style', 'transition: opacity 5s');
}
img.classList.toggle('fade');
}
function audioSwap() {
var audio = document.getElementById("my_audio");
var audioButton = document.getElementById("audioButton");
if(audio.paused == true){
audio.volume = 0.2;
audio.play();
audioButton.textContent = "Pause";
} else {
audio.pause();
audioButton.textContent = "Play";
}
}
function nestedPropertyDisplay() {
const info = {
name: "Nested Objects",
items: [{
id: 1,
identifier: 'FirstObject'
}, {
id: 2,
identifier: 'SecondObject'
}]
};
alert(info.name + " ID:" + info.items[0].id + " Identifer: " + info.items[0].identifier + " ID: " + info.items[1].id + " Identifer: " + info.items[1].identifier);
}
function validateForm(){
var colorsIndex = document.getElementById("colors").selectedIndex;
var colorsOptions = document.getElementById("colors").options;
var genderOptions = document.querySelector('input[name="gender"]:checked').value;
var userText = document.getElementById('textInput').value;
var checkboxes = document.getElementsByTagName("input");
var answers = document.getElementById('answers');
var displayInfo =
("\n\Your Color Choice: " + colorsOptions[colorsIndex].text) +
("\n\Your Gender: " + genderOptions) +
("\n\Your Text: " + userText) +
("\n\Your Animals: ");
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == "checkbox") {
if(checkboxes[i].checked == true){
displayInfo += checkboxes[i].value + ' ';
console.log('test');
}
}
}
answers.innerHTML = displayInfo;
}
function addObject() {
const x = document.createElement('object');
x.data = "snippet.html";
x.width = "100%";
x.height = "100px";
document.getElementById('domObjectDiv').appendChild(x);
}
function removeObject(){
var objects = document.getElementsByTagName('object');
objects[0].remove();
}
function positionObject() {
var objects = document.getElementsByTagName('object');
document.getElementById('formDiv').after(objects[0]);
}
function newListItem(){
var listOne = document.getElementById('listOne');
var newItem = document.createElement('li');
newItem.innerHTML = "New Item";
listOne.appendChild(newItem);
}
function moveList(){
var listOne = document.getElementById('listOne');
var listTwo = document.getElementById('listTwo');
var listTwoItems = listTwo.getElementsByTagName('li');
for(i = 0; i < listTwoItems.length; i++) {
listOne.appendChild(listTwoItems[i]);
}
}
function scrollToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}