-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
299 lines (263 loc) · 9.15 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
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
// Format for 01/31/2023
let today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = String(today.getFullYear());
let formatNumberDate = mm + "/" + dd + "/" + yyyy;
// Format for Jan/31/2023
let date;
let month;
let clickedDate = false;
switch (mm) {
case "01":
month = "Jan";
break;
case "02":
month = "Feb";
break;
case "03":
month = "Mar";
break;
case "04":
month = "April";
break;
case "05":
month = "May";
break;
case "06":
month="Jun";
break;
case "07":
month = 'Jul';
break;
case "08":
month = 'Aug';
break;
case "09":
month = "Sep";
break;
case "10":
month = "Oct";
break;
case "11":
month = "Nov";
break;
case "12":
month = "Dec";
break;
}
function switchDate() {
if (date.innerHTML.length == 10) {
date.innerHTML = month + "/" + dd + "/" + yyyy;
}
else {
date.innerHTML = formatNumberDate;
}
}
// Building the clock minute update
// Add them all together
let currentTime;
let getSeconds = today.getSeconds();
// Check for Am/Pm
let hours = today.getHours();
let postMeridiem;
if (hours >= 0 && hours < 12) {
postMeridiem = 'a.m.'
} else {
postMeridiem = 'p.m.'
}
// Get hours
setInterval(changeHour, 1000);
function changeHour() {
let updateToday = new Date();
let getMinutes = updateToday.getMinutes();
if (getMinutes == 0) {
hours = updateToday.getHours();
changeClock();
}
}
// Change current hour to 0-12
switch (hours) {
case 13:
hours = "1";
break;
case 14:
hours = "2";
break;
case 15:
hours = "3";
break;
case 16:
hours = "4";
break;
case 17:
hours = "5";
break;
case 18:
hours = "6";
break;
case 19:
hours = "7";
break;
case 20:
hours = "8";
break;
case 21:
hours = "9";
break;
case 22:
hours = "10";
break;
case 23:
hours = "11";
break;
case 0:
hours = "12";
break;
}
// Get minutes
setInterval(changeMinute, 1000);
let minutes = today.getMinutes();
function changeMinute() {
let updateToday = new Date();
let getSeconds = updateToday.getSeconds();
if (getSeconds == 0) {
minutes = updateToday.getMinutes();
changeClock();
}
}
function changeClock() {
currentTime = hours + ":" + minutes + " " + postMeridiem;
time.innerHTML = currentTime;
}
// Random color generator
let colorList = ["cadetblue", "darkcyan", "darkgreen", "black", "steelblue", "teal", "slategrey"];
let randomNumber = Math.floor(Math.random() * colorList.length);
function changeColor() { //Change color of background
if (document.body.style.backgroundColor != colorList[randomNumber]) {
document.body.style.backgroundColor = colorList[randomNumber];
} else {
document.body.style.backgroundColor = "#33475B";
}
}
let javaCode = `// window.onload = function() {
// let runTimeAddition = 5+2;
// let returnRunTime = "expression equals " + runTimeAddition + " at the runtime";
// document.getElementById("run-time").innerHTML = returnRunTime;
// }
// alert(addingRunTime);
// Learn breakpoints https://developer.chrome.com/docs/devtools/javascript/breakpoints/
// console.log('a');
// console.log('b');
// debugger;
// console.log('c');
// Read https://developer.chrome.com/docs/devtools/dom/#scroll2
// Go through https://developer.chrome.com/docs/devtools/css/grid/
// Go through the use of badges https://developer.chrome.com/docs/devtools/elements/badges/
// Go through spotting inactive CSS https://developer.chrome.com/docs/devtools/css/issues/
// Walk through using Devtools for flexbox https://developer.chrome.com/docs/devtools/css/flexbox/
// Go through resizing container with devtools https://developer.chrome.com/docs/devtools/css/container-queries/
// Skim through CSS devtools reference https://developer.chrome.com/docs/devtools/css/reference/
// Overview of the use of Console https://developer.chrome.com/docs/devtools/console/
// let clickCount = 0;
// $("#button-variables-number").addEventListener("click", () => {
// console.log('I was pressed $ {++clickCount} times by now');
// }); Doesn't work
// const coWorkers = [
// {
// name: 'daryl',
// age: 23
// },
// {
// name: 'linda',
// age: 31
// },
// {
// name: 'anthony',
// age: 25
// }
// ]
// setTimeout(() => { //setTimeout != setTimeOut
// console.table(coWorkers);
// }, 3000);
// console.assert(document.getElementById("variables-number"), 'variables-number not found!');
// const labelGroupName = 'SuperHero';
// console.group(labelGroupName);
// console.info('Iron Man');
// console.info('Spider Man');
// console.info('Captain America');
// console.groupEnd(labelGroupName);
// console.info('Thor');
// Go through https://developer.chrome.com/docs/devtools/console/log/
// Walk through https://developer.chrome.com/docs/devtools/javascript/
// Walk through https://developer.chrome.com/docs/devtools/console/javascript/
// $() used for document.querySelector() inspired by jQuery but not actually jQuery
// Learn live expressions https://developer.chrome.com/docs/devtools/console/live-expressions/
// Introduction to color display text in console https://developer.chrome.com/docs/devtools/console/format-style/
// Quickly scroll through console reference https://developer.chrome.com/docs/devtools/console/reference/
window.onload = () => {
let timer = document.getElementById('timer');
let before;
let after;
function startTimer() {
if (timer.innerHTML == 'Start timer') {
console.log('Starting timer');
before = Date.now();
timer.innerHTML = 'Stop timer';
}
else if (timer.innerHTML == 'Stop timer') {
console.log('Stopping timer');
after = Date.now();
console.log('Time ran = ' + (after-before) / 1000 + ' seconds');
timer.innerHTML = 'Start timer';
}
}
timer.addEventListener('click', startTimer);
let changeButton = document.getElementById('changeButton');
let changePara = document.getElementById('changePara');
changeButton.addEventListener('click', changeFunction);
function changeFunction() {
// let listOfWords = {
// header: 'What I like',
// paragraph: 'Juma',
// }
let arrayOfLikes = ['Juma', 'Coding', 'Learning', 'Finance'];
for (let i = 0; i < arrayOfLikes.length; i++) {
for (let k = 0; k < arrayOfLikes.length; k++) {
if (changePara.innerHTML == arrayOfLikes[i]) {
changePara.innerHTML = arrayOfLikes[k]
} else {
changePara.innerHTML = arrayOfLikes[Math.floor(Math.random() * arrayOfLikes.length)];
}
}
}
}
} // Help of https://stackoverflow.com/questions/53378613/console-time-in-second
// Skim through and go through console API reference https://developer.chrome.com/docs/devtools/console/api/g
// Skim through and watch video of console Utilities API https://developer.chrome.com/docs/devtools/console/utilities/
// Save code in devtools work space https://developer.chrome.com/docs/devtools/workspaces/
// Create run and save snippets https://developer.chrome.com/docs/devtools/sources/
// Create and run snippets https://developer.chrome.com/docs/devtools/javascript/snippets/gg
// Walk and skim through javascript devtools https://developer.chrome.com/docs/devtools/javascript/reference/
// Walk through and go through devtools Network https://developer.chrome.com/docs/devtools/network/
// Skim through Network references https://developer.chrome.com/docs/devtools/network/reference/
// Go through resrouces for devtools https://developer.chrome.com/docs/devtools/resources/
// Go through performances on devtools https://developer.chrome.com/docs/devtools/evaluate-performance/`
window.onload = () => {
// Give format date month/date/year
date = document.getElementById("todaysDate");
date.addEventListener("click", switchDate);
date.innerHTML = formatNumberDate;
// Time clock
time = document.getElementById("time");
currentTime = hours + ":" + minutes + " " + postMeridiem;
time.innerHTML = currentTime;
// Random Color
randomColor = document.getElementById("randomColor");
randomColor.innerHTML = colorList[randomNumber];
randomColor.addEventListener('click', changeColor);
//
// document.getElementById("#typed")
document.getElementById("javascriptCode").innerHTML = javaCode;
// javascript Code
}