-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
174 lines (158 loc) · 5.49 KB
/
script.js
File metadata and controls
174 lines (158 loc) · 5.49 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Get references to DOM elements
const coffeeInput = document.getElementById("coffeeInput");
const roundSelect = document.getElementById("roundSelect");
const generateRecipeBtn = document.getElementById("generateRecipeBtn");
const result = document.getElementById("result");
const recipeDetails = document.getElementById("recipeDetails");
const followUp = document.getElementById("followUp");
const yesBtn = document.getElementById("yesBtn");
const noBtn = document.getElementById("noBtn");
const additionalInputs = document.getElementById("additionalInputs");
const commanderClicks = document.getElementById("commanderClicks");
const waterTemp = document.getElementById("waterTemp");
const optionalItemsContainer = document.getElementById(
"optionalItemsContainer"
);
const finalRecipeBtn = document.getElementById("finalRecipeBtn");
const finalResult = document.getElementById("finalResult");
const finalDetails = document.getElementById("finalDetails");
// Coffee methods and optional items based on rounds
const coffeeMethods = {
"16ths": [
"Aeropress Original con filtros originales",
"Origami Resina con filtros cónicos Origami o planos Kalita",
"V60 Plastico con filtros cónicos Hario V02",
"Kalita Wave 185 con filtros planos Kalita",
"Chorreador Plinc con filtro Plinc",
],
"8ths": [
"Aeropress Original con filtros originales",
"Origami Resina con filtros cónicos Origami o planos Kalita",
"UFO con filtros Sibarist",
"V60 con filtros cónicos Hario V02",
"Chorreador Plinc con filtro Plinc",
],
"4ths": ["Aeropress Original", "Origami Resina", "V60", "UFO", "Graycano"],
semifinals: [
"Aeropress Original",
"Origami Resina",
"Brewista Tornado",
"Graycano",
"UFO",
],
finals: [
"Aeropress Original",
"Origami Resina",
"Brewista Tornado",
"Graycano",
"UFO",
],
};
// Optional items for rounds
const optionalItems = {
"4ths": [
"Third Wave Water Medium Roast Profile",
"Melodrip",
"Filtros Sibarist",
],
semifinals: [
"Third Wave Water Medium Roast Profile",
"Melodrip",
"Filtros Sibarist",
"Nucleus Paragon",
],
finals: [
"Third Wave Water Medium Roast Profile",
"Melodrip",
"Filtros Sibarist",
"Nucleus Paragon",
],
};
// Function to generate a random number in a range
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Variables to hold the recipe details
let selectedCoffee, selectedMethod, coffeeGrams, ratio;
// Function to generate the recipe
generateRecipeBtn.addEventListener("click", () => {
// Get user inputs
const coffeeList = coffeeInput.value
.split(",")
.map((coffee) => coffee.trim());
const selectedRound = roundSelect.value;
// Randomly select a coffee and a method based on the round
selectedCoffee = coffeeList[getRandomNumber(0, coffeeList.length - 1)];
selectedMethod =
coffeeMethods[selectedRound][
getRandomNumber(0, coffeeMethods[selectedRound].length - 1)
];
// Generate random coffee grams and ratio
coffeeGrams = getRandomNumber(12, 30);
let isAeropress = selectedMethod.includes("Aeropress");
if (isAeropress) {
ratio = "No se utiliza ratio, se requieren al menos 150ml de líquido.";
} else {
const ratioValue = getRandomNumber(10, 20);
ratio = `1:${ratioValue}`;
}
// Display the initial recipe
result.classList.remove("hidden");
recipeDetails.innerHTML = `
<strong>Café a usar:</strong> ${selectedCoffee} <br>
<strong>Método a usar:</strong> ${selectedMethod} <br>
<strong>Gramos a usar:</strong> ${coffeeGrams}g <br>
<strong>Ratio a usar:</strong> ${ratio}
`;
// Show follow-up options
followUp.classList.remove("hidden");
});
// Handling Yes and No buttons
yesBtn.addEventListener("click", () => {
// Show additional inputs for clicks, water temp, and optional items
additionalInputs.classList.remove("hidden");
// Get selected round
const selectedRound = roundSelect.value;
// Display optional items based on the selected round
const optionalItemsList = optionalItems[selectedRound] || [];
optionalItemsContainer.innerHTML = optionalItemsList
.map(
(item) => `
<div>
<input type="checkbox" id="${item}" name="optionalItems" value="${item}">
<label for="${item}">${item}</label>
</div>
`
)
.join("");
finalDetails.classList.remove("hidden");
});
noBtn.addEventListener("click", () => {
// Hide everything
result.classList.add("hidden");
followUp.classList.add("hidden");
additionalInputs.classList.add("hidden");
finalDetails.classList.add("hidden");
});
// Final recipe generation
finalRecipeBtn.addEventListener("click", () => {
// Get additional inputs
const clicks = commanderClicks.value;
const temp = waterTemp.value;
const selectedOptionalItems = Array.from(
document.querySelectorAll('input[name="optionalItems"]:checked')
)
.map((item) => item.value)
.join(", ");
// Display the final recipe details
finalResult.classList.remove("hidden");
finalDetails.innerHTML = `
<strong>Café seleccionado:</strong> ${selectedCoffee} <br>
<strong>Método a usar:</strong> ${selectedMethod} <br>
<strong>Gramos a usar:</strong> ${coffeeGrams}g <br>
<strong>Ratio a usar:</strong> ${ratio} <br>
<strong>Clicks en comandante:</strong> ${clicks} <br>
<strong>Temperatura del agua:</strong> ${temp}°C <br>
<strong>Items opcionales usados:</strong> ${selectedOptionalItems}
`;
});