-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (42 loc) · 1.16 KB
/
script.js
File metadata and controls
63 lines (42 loc) · 1.16 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
window.addEventListener('DOMContentLoaded',init, false);
function init() {
alert('WELCOME. Lets have some fun with JavaScript');
}
function changeBackgroundColor() {
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
document.body.style.backgroundColor = "#" + randomColor;
}
function startCountdown(seconds) {
let timeLeft = seconds;
const intervalId = setInterval(() => {
if (timeLeft === -1) {
clearInterval(intervalId);
alert("Time's up!");
} else {
document.getElementById("timer").textContent = timeLeft;
timeLeft--;
}
}, 1000);
}
const funFacts = [
"Honeybees can recognize human faces.",
"The moon experiences moonquakes.",
"Ice pops were invented by accident in 1905.",
"Flamingos aren't born pink",
];
function displayFunFact() {
const randomIndex = Math.floor(Math.random() * funFacts.length);
alert(funFacts[randomIndex]);
}
function moveBox() {
const box = document.getElementById("box");
let x = 0;
const intervalId = setInterval(() => {
if (x >= 300) {
clearInterval(intervalId);
} else {
x++;
box.style.left = x + "px";
}
}, 10);
}