-
Notifications
You must be signed in to change notification settings - Fork 248
/
script.js
63 lines (51 loc) · 1.5 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
"use strict";
const titleElement = document.querySelector(".title");
const buttonsContainer = document.querySelector(".buttons");
const yesButton = document.querySelector(".btn--yes");
const noButton = document.querySelector(".btn--no");
const catImg = document.querySelector(".cat-img");
const MAX_IMAGES = 5;
let play = true;
let noCount = 0;
yesButton.addEventListener("click", handleYesClick);
noButton.addEventListener("click", function () {
if (play) {
noCount++;
const imageIndex = Math.min(noCount, MAX_IMAGES);
changeImage(imageIndex);
resizeYesButton();
updateNoButtonText();
if (noCount === MAX_IMAGES) {
play = false;
}
}
});
function handleYesClick() {
titleElement.innerHTML = "Yayyy!! :3";
buttonsContainer.classList.add("hidden");
changeImage("yes");
}
function resizeYesButton() {
const computedStyle = window.getComputedStyle(yesButton);
const fontSize = parseFloat(computedStyle.getPropertyValue("font-size"));
const newFontSize = fontSize * 1.6;
yesButton.style.fontSize = `${newFontSize}px`;
}
function generateMessage(noCount) {
const messages = [
"No",
"Are you sure?",
"Pookie please",
"Don't do this to me :(",
"You're breaking my heart",
"I'm gonna cry...",
];
const messageIndex = Math.min(noCount, messages.length - 1);
return messages[messageIndex];
}
function changeImage(image) {
catImg.src = `img/cat-${image}.jpg`;
}
function updateNoButtonText() {
noButton.innerHTML = generateMessage(noCount);
}