-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (74 loc) · 2.94 KB
/
script.js
File metadata and controls
87 lines (74 loc) · 2.94 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
85
86
87
// 1. Define elements at the top so everyone can use them
const problem = document.getElementById("problem");
const difficulty = document.getElementById("difficulty");
const energy = document.getElementById("energy");
const submitBtn = document.getElementById("submitBtn");
const result = document.getElementById("result");
const validateForm = () => {
let isValid = true;
// Difficulty Check
const diffValue = parseFloat(difficulty.value);
if (isNaN(diffValue) || diffValue < 0 || diffValue > 10 || !Number.isInteger(diffValue)) {
difficulty.setCustomValidity("Kérlek, adj meg egy egész számot 0 és 10 között!");
isValid = false;
} else {
difficulty.setCustomValidity("");
}
// Problem Select Check (Matches value="0" in your HTML)
if (problem.value === "0") {
problem.setCustomValidity("Kérlek, válaszd ki, ki okozta a hibát!");
isValid = false;
} else {
problem.setCustomValidity("");
}
// Energy Select Check (New validation!)
if (energy.value === "0") {
energy.setCustomValidity("Kérlek, válaszd ki a munkakedv szinteded!");
isValid = false;
} else {
energy.setCustomValidity("");
}
if (!isValid) {
energy.reportValidity();
difficulty.reportValidity();
problem.reportValidity();
}
return isValid;
};
submitBtn.addEventListener("click", () => {
if (validateForm()) {
result.innerHTML = calculation();
} else {
result.innerHTML = "";
}
});
function calculation() {
const sum = Number(problem.value) + Number(difficulty.value) + Number(energy.value);
if (sum < 5) {
return `<span>${lowScore[Math.floor(Math.random() * lowScore.length)]}</span>`;
} else if (sum > 12) {
return `<span>${highScore[Math.floor(Math.random() * highScore.length)]}</span>`;
} else {
return `<span>${betweenScore[Math.floor(Math.random() * betweenScore.length)]}</span>`;
}
}
const highScore = new Array(
"Nem kell megcsinálnom, mert nö vagyok.",
"Azt se értem, hogy miröl van szó!",
"Majd a Viktor megcsinálja.",
"Hát pedig én biztos nem fogom megcsinálni!",
"HOGY MIVAAAN? Azt, a nagy lófaszt csinálom meg!",
'Dehogy csinálom meg, "mások" sem szokták.');
const betweenScore = new Array(
"Megcsinálom, úgyis unatkozok.",
"Megcsinálom, hogy elhiggyék, hogy én is csinálok valamit.",
"*nyögdécselés... Most tényleg kelljek fel emiatt? (igen)",
"Faszomnak sincs kedve kiteregtni. (és nem is fogok)"
);
const lowScore = new Array(
"Ezt elolvasom, azt megyek.",
"Faszomnak sincs kedve kiteregtni. (de attól még ki fogok)",
"Majd megkérdezem a Viktort, hátha megcsinálja.",
"<i>*nyögdécselés...</i> Most tényleg kelljek fel emiatt? (nem)",
"<i>*szimplán mérgelödik és megcsinálja</i>"
);