-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
81 lines (67 loc) · 2.09 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"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 = 10;
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();
resizeNoButton();
updateNoButtonText();
if (noCount === MAX_IMAGES) {
play = false;
}
} else if (noCount === 13) noButton.style.display = "none";
});
function handleYesClick() {
titleElement.innerHTML = "Siiiiii!!!! 😍😍😍";
buttonsContainer.classList.add("hidden");
changeImage("yes");
window.navigator.vibrate(2000);
catImg.addEventListener(
"dblclick",
() => (titleElement.innerHTML = "Hecho con amor por EduardoProfe666🎩")
);
}
function resizeYesButton() {
const computedStyle = window.getComputedStyle(yesButton);
const fontSize = parseFloat(computedStyle.getPropertyValue("font-size"));
const newFontSize = fontSize * 1.3;
yesButton.style.fontSize = `${newFontSize}px`;
}
function resizeNoButton() {
const computedStyle = window.getComputedStyle(noButton);
const fontSize = parseFloat(computedStyle.getPropertyValue("font-size"));
noButton.style.fontSize = `${fontSize * 0.9}px`;
}
function generateMessage(noCount) {
const messages = [
"No",
"Estás segura?",
"Por favorcito",
"Perdóname chica anda",
"No seas mala",
"Yo no lo vuelvo a hacer...",
"Discúlpame pls",
"Anda mi amor perdóname",
"No me hagas esto :(",
"Me rompes el corazón",
"Quiero llorar...",
];
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);
}