-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (72 loc) · 2.22 KB
/
script.js
File metadata and controls
84 lines (72 loc) · 2.22 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
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
const answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy, try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful",
];
function shake() {
const input = document.getElementById("question").value.trim();
const answer = document.getElementById("answer");
const ball = document.getElementById("ball");
if (input === "") {
answer.textContent = "Please ask a question.";
return;
}
let sndfjsd = false;
if (input === "yo gurt" || input === "yogurt") {
sndfjsd = true;
}
// ball.classList.remove("shake");
// void ball.offsetWidth; //thank you copilot!
// ball.classList.add("shake");
answer.style.opacity = 0;
const shakes = 4;
const delay = 250;
for (let i = 0; i < shakes; i++) {
setTimeout(() => {
var randX = Math.floor(Math.random() * 51) - 25;
var randY = Math.floor(Math.random() * 51) - 25;
var randR = Math.floor(Math.random() * 41) - 20;
ball.style.transform = `translate(${randX}px, ${randY}px) rotate(${randR}deg)`;
}, i * delay);
setTimeout(() => {
ball.style.transition = "";
ball.style.transform = "translate(0px, 0px) rotate(0deg)";
}, i * delay + 200);
}
let response = "default";
if (!sndfjsd) {
response = answers[Math.floor(Math.random() * answers.length)];
} else {
response = "gurt: yo";
}
setTimeout(() => {
answer.textContent = response;
answer.style.opacity = 1;
}, shakes * delay + 300);
}
document.getElementById("button").addEventListener("click", shake);
document.getElementById("question").addEventListener("keypress", function (e) {
if (e.key === "Enter") {
shake();
}
});
particlesJS.load('scene', 'particles.json', function() {
console.log('callback - particles.js config loaded');
});