forked from fbw-p23-e05/kitty-rescue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (31 loc) · 1.06 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
const button = document.getElementById('btn');
const input = document.getElementById('amount');
const cat = document.getElementById('cat');
function handleDonation() {
const amount = input.value;
if (amount == 0) {
alert('Thanks for nothing, the cats are all sad :(');
document.body.style.background = 'red';
} else {
alert(`Thanks for the donation of $ ${amount}!`);
}
}
function catClick() {
document.body.style.background = 'pink';
}
function moveCat() {
const maxX = window.innerWidth - cat.width;
const maxY = window.innerHeight - cat.height;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * maxY);
cat.style.left = randomX + "px";
cat.style.top = randomY + "px";
}
function toggleCatClass() {
cat.classList.toggle("rotate");
}
button.addEventListener('click', handleDonation);
cat.addEventListener('click', catClick);
cat.addEventListener('click', moveCat);
cat.addEventListener('mouseover', toggleCatClass);
cat.addEventListener('mouseout', toggleCatClass);