-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveWebConsole.js
313 lines (202 loc) · 6.94 KB
/
LiveWebConsole.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// * * * * * WELCOME TO JS EXPLORATIONS IN THE DOM * * * * * //
// ¿where are we? in the browser's web console!
navigator.userAgent
window.innerWidth
window.innerHeight
// console.log() is a function in JavaScript that writes a message to in the web console usually for debugging purposes;
// log the console object itself — this command will output the various properties of the console object as the browser knows them
console.log(console);
console.error();
console.clear();
// object arrays and strings
console.log({object: 'object'}, {object: 'object'});
console.log(['array', 'array'], ['array', 'array']);
console.log('This is a number: %i', 42);
// the undefined is the return value of console.log()
console.log('%cHELL0!', 'color: blue; font-size: 100px;');
console.log('%cHiya!', `
background: blue;
border: 3px solid pink;
color: pink;
font-size: 50px;
padding: 20px;
`);
// * * * * * ALERT MESSAGES * * * * * //
alert('Hello, world!')
function hello() {
alert('Hello, world!')
}
hello()
// * * * * * JS FUNCTIONS
var hello;
hello = function() {
alert('Hello, world!')
}
hello()
// or try the arrow function
// if the function has only one statement, and the statement returns a value,
// you can remove the brackets;
var hello;
hello = () => { alert('Hello, world!') }
hello()
// * * * * * VARIABLES
// var x = 10;
// here x is 10
{
var x = 2; // block Scope: here x is 2
}
// console.log(x); // here x is 2
// variables declared Locally (inside a function) have Function Scope.
// var x = 10;
function name() {
var x = 2;
console.log(x); // code here can use x
}
// name()
// for debugging purposes, you can call the console.log() method in the browser to display data
// var: function scoped VS let: block scoped
function anothername() {
var x = 2;
let y = 3;
console.log(x, y);
{
let x = "100";
console.log(x); // 100
}
console.log(x); // 2
}
anothername();
// CONST can't be reassigned and is block scoped
// you’re signalling to your future self as well as any other future developers that have to read your code that this variable shouldn’t change
// const y = 50;
// y = 100; // ReferenceError
// JavaScript variables can hold many data types: numbers, strings, objects and more;
// all JavaScript identifiers are case sensitive;
// JavaScript does not interpret VAR or Var as the keyword var;
var length = 205; // Number
var lastName = "Lovelace"; // Strings store text, you write them in between single or double quotes;
var x = {firstName:"Ada", lastName:"Lovelace"}; // Objects are variables too that can contain many values.
// * * * * * ARRAY * * * * * //
var fruits = ["Almond", "Apple", "Chili pepper"];
fruits.sort();
// console.log(fruits[0]);
fruits.reverse();
// console.log(fruits[0]);
document.getElementById("empty").innerHTML = fruits[0];
// * * * * * OBJECTS
var person = {firstName:"Ada", lastName:"Lovelace", age:"205"};
var person = {
firstName: "Ada",
lastName: "Lovelace",
age: 205,
};
// display some data from the object:
document.getElementById("empty").innerHTML = person.firstName + " is " + person.age + " years old.";
// JavaScript has a Boolean data type. It can only take the values true or false.
let isPending = false;
let isDone = true;
console.log(typeof(isPending));
console.log(typeof(isDone));
// Boolean(10 > 9)
// Display a string:
var txt = "You can display the lenght of this text on the empty div";
document.getElementById("empty").innerHTML = txt.length; // counts empty spaces
document.getElementById("empty").innerHTML = "Hello World!";
// * * * * * IF STATEMENTS * * * * * //
if (1 + 1 == 2) console.log("It's true");
// * * * * * LOOPS * * * * * //
let icons = "🌍 🖥️ 🌟";
for (let char of icons) {
console.log(char);
}
// excerpt From: Marijn Haverbeke, 'Eloquent JavaScript'
// scroll to top
function scrollWin() {
window.scrollTo(0, 0);
}
// * * * * * CHANGING STYLE * * * * * //
document.body.style.background = "url()"
var x = document.querySelector("h1")
x.style.color="pink"
// adding your prefered colour as a parameter
function changeColor(newColor) {
var elem = document.getElementById('title');
elem.style.color = newColor;
}
changeColor('blue')
// creating a loop for changing text in all headings
var elements = document.getElementsByTagName("h3")
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = "foo";
}
// * * * * * TIMING EVENTS * * * * * //
// setInterval(function, milliseconds)
// same as setTimeout(), but repeats the execution of the function continuously.
// ADDING AN INTERVAL TO AN ARRAY
colors = new Array("#FFF", "#202020 ", "#859de4 ","#fdf56d" ,"#b8ffeb ", "#404040 ", "#cc92ba")
colorIndex = 0
idInterval = 0
function colourify () {
document.querySelector('body').style.backgroundColor = colors[colorIndex];
colorIndex = (colorIndex + 1) % colors.length;
}
colourify ()
setInterval("colourify()", 800);
// EVENT LISTENERS
// eventListener() method attaches an event handler to the specified element
// if the viewport is less than, or equal to, 600 pixels wide,
// change the background color to pink. If it is greater than 600, change it to aquamarine
var mediaQueryList = window.matchMedia('(max-width: 600px)');
function screenTest(e) {
if (e.matches) {
/* the viewport is 600 pixels wide or less */
document.body.style.backgroundColor = 'pink';
} else {
/* the viewport is more than than 600 pixels wide */
document.body.style.backgroundColor = 'aquamarine';
}
}
// * * * * * CHOREOGRAPHIC CODING * * * * * //
function stretching () {
document.querySelector("").style.transform="skew(60deg)"
}
transform: matrix3d(1, 1, 0, 0, 10, 1, 0, 10, 10, 0, 1, 0, 200, 10, 0, 1);
filter: grayscale(100%)
opacity: 0.25;
var currentZoom = 100;
function Breathe (paramvar) {
currentZoom += paramvar;
document.body.style.zoom = currentZoom + "%"
}
// Breathe (+100);
function Breathing() {
var zooming = document.querySelector("body");
currentScale = 1;
currenttime = setInterval(function() {
zooming.style.transform="scale(" + currentScale + ")";
currentScale = Math.random() * 5
}, 800);
}
function No_Breathing() {
clearInterval(currenttime);
}
var delay="10"; //how many seconds
var count='0';
var Texts=new Array();
Texts[0]="choreographies suspend certainty,";
Texts[1]="choreographies model uncertain outcomes,";
Texts[2]="choreographies may also refuse to act,";
Texts[3]="choreographies valorize failure,";
Texts[4]="choreographies traject ideas into the action of perception"
// quotes by William Forsythe;
function New_Sequence_or_Phrasing() {
document.querySelector('').innerHTML=Texts[count];
count++;
if(count==Texts.length){count='0';}
setTimeout("New_Sequence_or_Phrasing()",delay*100);
}
New_Sequence_or_Phrasing()
function Off_Stage () {
document.body.innerHTML = '';
document.head.innerHTML = '';
}