-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
258 lines (212 loc) · 6.79 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
var cars = ["Saab","Volvo","BMW"];
var changedb = false;
var rarray = [];
function myFunction() {
document.getElementById("demo").innerHTML = 5 + 6;
this.class = "active";
}
function redoFunc() {
document.write('<input type="button" value="Back" onclick="goBack()">');
}
function goBack() {
window.location.reload();
}
function alertJ() {
window.alert("Hello i am an alert!");
}
function varTest() {
var x, y, z, result;
x = "here is a statement: "
y = 8;
z = 9;
result = y + z;
document.getElementById("demo").innerHTML = x + result;
}
function arrTest() {
document.getElementById("demo").innerHTML = cars;
}
function objectTest() {
var listo = {firstname:"Thys", Lastname:"Wentzel", Age:22};
document.getElementById("demo").innerHTML = listo.firstname + "<br>" + listo.Lastname + "<br>" + listo.Age;
}
function cal( value1, value2) {
return value1 * value2;
}
function functionTest () {
document.getElementById("demo").innerHTML = cal( 4, 5) + " has been calculated with a function";
}
function globalTest() {
if(changedb == false)
{
changedb = true;
document.getElementById("testb1").innerHTML = "Look at me!!! Click again!!!";
}
else
{
changedb = false;
document.getElementById("testb1").innerHTML = "Sad and dull. click again";
}
}
function randomT() {
document.getElementById("demo").innerHTML = "Here is a random number between 1 and 100: " + (Math.floor(Math.random() * 100) + 1);
}
function dateT() {
document.getElementById("demo").innerHTML = new Date();
}
function loopT() {
var text = "<ul>"
var objects = ["person","car","house"]
for(var i = 0; i < objects.length; i++)
{
text += "<li>" + objects[i] + "</li>";
}
document.getElementById("demo").innerHTML = text;
}
function arrTest() {
var cars = ["volvo","opel","BMW"];
document.getElementById("demo").innerHTML = cars.join("<br>");
}
function sinput() {
document.getElementById("demo").innerHTML = "<input type='number' id='age' value='18'><button type='button' onclick='process()'>Test</button><br><p id='result'>Result goes here</p><br>";
}
function process() {
var age = Number(document.getElementById("age").value);
var text;
if(age < 18)
text = "Too young";
else if(age >= 18)
text = "Old enough";
document.getElementById("result").innerHTML = text + " to vote";
}
function switchTest() {
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document.getElementById("demo").innerHTML = day;
}
function inList() {
rarray = [];
document.getElementById("demo").innerHTML = "<input id='searchtxt' type='text' value='Hello'><button type='button' onclick='process2()'>Add Value</button><br><p id='result'>Result goes here</p><br>";
}
function process2() {
var word = document.getElementById("searchtxt").value;
rarray.push(word);
display();
}
function remove(i){
rarray.splice(i,1)
display();
}
function display() {
var par = "";
for(var k = 0; k < rarray.length; k++)
{
par += "<div>" + rarray[k] + "<button type=button onclick='remove(" + k + ")' style='margin-left:10px'>Remove</button></div>"
}
document.getElementById("result").innerHTML = par;
}
function randomcol() {
document.getElementById("demo").innerHTML = "<button class='circ' onclick='changecol()' id='circbut'>Change the color</button>";
}
function changecol() {
var num = Math.floor(Math.random() * 5);
switch (num) {
case 0:
document.getElementById("circbut").style.backgroundColor = "blue";
break;
case 1:
document.getElementById("circbut").style.backgroundColor = "red";
break;
case 2:
document.getElementById("circbut").style.backgroundColor = "green";
break;
case 3:
document.getElementById("circbut").style.backgroundColor = "yellow";
break;
case 4:
document.getElementById("circbut").style.backgroundColor = "white";
}
}
function drop() {
document.getElementById("demo").innerHTML = "<div><select id='selecti' value='hello'><option value='hello'>hello</option><option value='hi'>hi</option><option value='nice'>nice</option><option value='bye'>bye</option></select><button type='button' onclick='getIndex()'>Check value</button></div><br><div id='index'>Results here</div>";
}
function getIndex() {
var e = document.getElementById("selecti");
var strUser = e.options[e.selectedIndex].value;
document.getElementById("index").innerHTML = "The value is: " + strUser;
}
function animatel() {
document.getElementById("demo").innerHTML = "<div style='text-align:center'><button type='button' onclick='myMove()'>Animate!</button></div><br><div id ='container'><div id ='animate'></div></div>";
}
function myMove() {
var elem = document.getElementById("animate");
var pos1 = 0;
var pos2 = 0;
var pos3 = 350;
var pos4 = 350;
var move = false;
var id = setInterval(frame, 10);
var stop = false;
function frame() {
/*if(stop == true){
clearInterval(id)
}else */if(pos1 <= 350){
pos1++;
elem.style.top = pos1 + 'px';
}else if(pos2 <= 350){
pos2++;
elem.style.left = pos2 + 'px';
}else if(pos3 >= 0){
pos3--;
elem.style.top = pos3 + 'px';
}else if(pos4 >= 0){
pos4--;
elem.style.left = pos4 + 'px';
if(pos4 == 0){
pos1 = 0;
pos2 = 0;
pos3 = 350;
pos4 = 350;
}
}
}
}
function confirms() {
var txt;
txt = prompt("Enter something");
document.getElementById("dmsg").innerHTML = txt;
}
function message1() {
}
function otherone() {
var txt;
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("dms").innerHTML = txt;
}
function showmsg() {
document.getElementById("demo").innerHTML = '<button onclick="confirms()">Try it</button><br><p id="dmsg">Your message goes here</p><br><button onclick="otherone()">Try it</button><br><p id="dms">Yes or no</p>';
}