-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsync Mini Projects
More file actions
61 lines (48 loc) · 1.6 KB
/
Copy pathAsync Mini Projects
File metadata and controls
61 lines (48 loc) · 1.6 KB
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
Projects based on Java Script (JS Code goes here)
*** Async JS ***
****************************************************************************************** Project 1 ***************************************************************************************************************
//***Generate a random color***
const randomColor = function () {
const hex = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += hex[Math.floor(Math.random() * 16)];
}
return color;
};
let intervalId;
const startChangingColor = function () {
if (!intervalId) {
intervalId = setInterval(changeBgColor, 1000);
}
function changeBgColor() {
document.body.style.backgroundColor = randomColor();
}
};
const stopChangingColor = function () {
clearInterval(intervalId);
intervalId = null;
};
document.querySelector('#start').addEventListener('click', startChangingColor);
document.querySelector('#stop').addEventListener('click', stopChangingColor);
************************************************************************************************** Project 2 ********************************************************************************************************
//*** Key pressed , Key Code ***
const insert = document.getElementById('insert');
window.addEventListener('keydown', (e) => {
insert.innerHTML = `
<div class='color'>
<table>
<tr>
<th>Key</th>
<th>Keycode</th>
<th>Code</th>
</tr>
<tr>
<td>${e.key === ' ' ? 'Space' : e.key}</td>
<td>${e.keyCode}</td>
<td>${e.code}</td>
</tr>
</table>
</div>
`;
});