-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
179 lines (179 loc) · 8.73 KB
/
script.js
File metadata and controls
179 lines (179 loc) · 8.73 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
175
176
177
178
179
const ingredientSubstitutes = {
"butter": "1/4 cup oil or margarine",
"oil": "1 cup applesauce (for baking)",
"applesauce": "1/4 cup mashed banana",
"mashed banana" :"1 cup oil",
"yogurt": "1 cup sour cream or buttermilk",
"coconut oil": "1 cup butter or margarine",
"margarine": "1 cup butter",
"sour cream": "1 cup Greek yogurt",
"Greek yogurt": "1 cup sour cream",
"heavy cream": "1 cup milk + 1/4 cup butter",
"milk": "1 cup almond milk or oat milk",
"flour": "1 cup almond flour or gluten-free flour",
"almond flour": "1 cup regular flour",
"gluten-free flour": "1 cup regular flour"
};
const flavorPairings = {
"chicken": ["garlic", "thyme", "rosemary", "lemon", "parsley"],
"beef": ["garlic", "rosemary", "bay leaves", "thyme", "shrimp"],
"salmon": ["dill", "lemon", "garlic", "chives"],
"pasta": ["basil", "garlic", "parmesan", "tomato", "salmon", "beef"],
"tofu": ["soy sauce", "ginger", "garlic", "sesame oil"],
"chocolate": ["vanilla", "coffee", "salt", "peanut butter", "banana"],
"cheese": ["wine", "fruit", "nuts", "bread", "pineapple"],
"egg": ["cheese", "spinach", "mushrooms", "bacon", "toast"],
"potato": ["cheese", "sour cream", "chives", "bacon", "salt", "potato"]
};
document.getElementById("substitute-btn").addEventListener("click", suggestSubstitute);
document.getElementById("time-calc-btn").addEventListener("click", calculateTime);
document.getElementById("temp-calc-btn").addEventListener("click", calculateRequiredTemperature);
document.getElementById("pairing-btn").addEventListener("click", suggestFlavorPairing);
document.getElementById("coin-flip-btn").addEventListener("click", flipCoin);
document.getElementById("add-timer-btn").addEventListener("click", addTimer);
function suggestSubstitute() {
const ingredient = document.getElementById("ingredient-substitution").value.toLowerCase();
const result = document.getElementById("substitute-result");
if (ingredientSubstitutes[ingredient]) {
result.textContent = `The wizard dude says the substitute for ${ingredient}: ${ingredientSubstitutes[ingredient]}`;
} else {
result.textContent = "Sorry dude no substitute I know of.";
}
}
function calculateTime() {
const originalTime = parseInt(document.getElementById("original-time").value);
const originalQuantity = parseInt(document.getElementById("original-quantity").value);
const scaledQuantity = parseInt(document.getElementById("scaled-quantity").value);
const temperature = parseInt(document.getElementById("temperature").value);
const unit = document.getElementById("unit-toggle").value;
const recipeType = document.getElementById("recipe-type").value;
const result = document.getElementById("time-result");
if (isNaN(originalTime) || isNaN(originalQuantity) || isNaN(scaledQuantity) || isNaN(temperature) ||
originalTime <= 0 || originalQuantity <= 0 || scaledQuantity <= 0 || temperature <= 0) {
result.textContent = "Oh yeah lemme just make up data. Fill in all the fields dude";
return;
}
let tempInFahrenheit = temperature;
if (unit === "C") {
tempInFahrenheit = (temperature * 9 / 5) + 32;
}
let scalingExponent = 1;
if (recipeType === "boil" || recipeType === "stovetop") scalingExponent = 0.8;
let scaledTime = originalTime * Math.pow((scaledQuantity / originalQuantity), scalingExponent);
if (tempInFahrenheit > 375) {
scaledTime *= 0.85;
} else if (tempInFahrenheit < 325) {
scaledTime *= 1.05;
}
result.textContent = `New cooking time for ${scaledQuantity} servings at ${tempInFahrenheit}°F: ${scaledTime.toFixed(2)} minutes.`;
}
function calculateRequiredTemperature() {
const originalTime = parseInt(document.getElementById("original-time").value);
const originalQuantity = parseInt(document.getElementById("original-quantity").value);
const scaledQuantity = parseInt(document.getElementById("scaled-quantity").value);
const targetTime = parseInt(document.getElementById("target-time").value);
const recipeType = document.getElementById("recipe-type").value;
const tempResult = document.getElementById("temp-result");
if (isNaN(originalTime) || isNaN(originalQuantity) || isNaN(scaledQuantity) || isNaN(targetTime) ||
originalTime <= 0 || originalQuantity <= 0 || scaledQuantity <= 0 || targetTime <= 0) {
tempResult.textContent = "Please enter valid inputs for all fields.";
return;
}
const timeScalingFactor = targetTime / originalTime;
let baseTemperature = 350;
if (recipeType === "bake") {
baseTemperature = 350;
} else if (recipeType === "boil") {
baseTemperature = 212;
} else if (recipeType === "grill") {
baseTemperature = 400;
} else if (recipeType === "stovetop") {
baseTemperature = 300;
}
let requiredTemperature = baseTemperature * Math.pow(timeScalingFactor, 1);
tempResult.textContent = `Required temperature to cook ${scaledQuantity} servings in ${targetTime} minutes: ${Math.round(requiredTemperature)}°F.`;
}
function suggestFlavorPairing() {
const ingredient = document.getElementById("flavor-pairing").value.toLowerCase();
const result = document.getElementById("pairing-result");
if (flavorPairings[ingredient]) {
result.textContent = `Flavor pairings for ${ingredient}: ${flavorPairings[ingredient].join(", ")}`;
} else {
result.textContent = "Sorry, no flavor pairings found for this ingredient."; //dead code but I dont wanna bother removing :p futrure karol problem
}
}
function flipCoin() {
const ingredient1 = document.getElementById("coin-ingredient-1").value.toLowerCase();
const ingredient2 = document.getElementById("coin-ingredient-2").value.toLowerCase();
const result = document.getElementById("coin-result");
if (!ingredient1 || !ingredient2) {
result.textContent = "Please enter both ingredients.";
return;
}
if((ingredient1=='drinking'&&ingredient2=='driving'||(ingredient1=="driving")&&ingredient2=='drinking'))
{
result.textContent = "HUGE HELL YEA. THATS FIVE BIG BOOMS. BOOM. BOOM. BOOM. BOOM. BOOM."
return
}
const outcome = Math.random() < 0.5 ? "Hell yea" : "Prob not";
result.textContent = `Will ${ingredient1} pair with ${ingredient2}? ${outcome}`;
}
let timerCount = 0;
function addTimer() {
timerCount++;
const timersContainer = document.getElementById("timers-container");
const timerDiv = document.createElement("div");
timerDiv.classList.add("timer");
const timerNameInput = document.createElement("input");
timerNameInput.type = "text";
timerNameInput.placeholder = "Timer Name";
timerNameInput.classList.add("timer-name");
const timerInput = document.createElement("input");
timerInput.type = "number";
timerInput.placeholder = "Minutes";
timerInput.classList.add("timer-duration");
const timerSecondsInput = document.createElement("input");
timerSecondsInput.type = "number";
timerSecondsInput.placeholder = "Seconds";
timerSecondsInput.classList.add("timer-duration");
const startButton = document.createElement("button");
startButton.textContent = "Start Timer";
startButton.onclick = function() {
startTimer(timerNameInput.value, timerInput.value, timerSecondsInput.value);
};
const timerDisplay = document.createElement("p");
timerDisplay.classList.add("timer-display");
timerDisplay.textContent = "";
timerDiv.appendChild(timerNameInput);
timerDiv.appendChild(timerInput);
timerDiv.appendChild(timerSecondsInput);
timerDiv.appendChild(startButton);
timerDiv.appendChild(timerDisplay);
timersContainer.appendChild(timerDiv);
}
function startTimer(name, minutes, seconds) {
if (!name || (!minutes && !seconds) || (minutes <= 0 && seconds <= 0)) {
alert("One trillion seconds until ur court trial. Maybe next time put in some valid inputs dawg");
return;
}
const totalTime = (parseInt(minutes) || 0) * 60 + (parseInt(seconds) || 0); // Convert to seconds
let remainingTime = totalTime;
const timerDisplay = document.querySelector(".timer-display:last-child");
timerDisplay.textContent = `${name}: ${formatTime(remainingTime)}`;
const timerInterval = setInterval(() => {
if (remainingTime <= 0) {
clearInterval(timerInterval);
alert(`${name} timer is up!`);
timerDisplay.textContent = `${name}: Time's up!`;
} else {
remainingTime--;
timerDisplay.textContent = `${name}: ${formatTime(remainingTime)}`;
}
}, 1000);
}
function formatTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}m ${seconds}s`;
}
addTimer();