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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Berechnet die Preise für Pizza im Verhältnis zum Flächeninhalt. Lieber zwei kleine oder eine große Pizza kaufen?">
<link rel='stylesheet' type='text/css' href="/css/bootstrap.min.css">
<link rel='icon' href="/img/paw-144.png">
<link rel="manifest" href="/manifest.json">
<title>Wie teuer ist eine Pizza im Verhältnis zum Flächeninhalt?</title>
<meta name="theme-color" content="#fd8a02">
<style>
html {
width: 100%;
}
.main {
margin-top: 1rem;
}
.show-pizza {
height: 10cm;
width: 10cm;
background-color: #a10a09;
border-radius: 50%;
margin-left: 10px;
margin-top: 20px;
border: 0.5cm solid #fff38a;
}
math {
font-size: 1.5rem;
}
.btn-tertiary {
background-color: #fd8a02;
margin-left: .01rem;
}
.btn-tertiary:hover {
filter: brightness(0.85);
}
.btn-hide {
background-color: grey;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<div class="container main">
<h1>Wie teuer ist eine Pizza im Verhältnis zum Flächeninhalt?</h1>
<p>Auch bekannt als: Sollte man die kleinere oder größere Pizza nehmen? Ist es günstiger zwei Pizzen zu kaufen, oder eine zu teilen?</p>
<!-- Flächeninhalt: π * r^2
Umfang: π * d
-->
<form id="preis">
<label id="pizza-label-1" class="hidden">
<h2>Erste Pizza</h2>
</label>
<div class="form-group">
<label for="d1">Durchmesser in cm:</label>
<input id="d1" class="form-control" type="number" step="0.1" placeholder="Durchmesser in cm" required>
</div>
<div class="form-group">
<label for="p1">
Preis in Euro:
</label>
<input id="p1" class="form-control" type="number" step="0.1" placeholder="Preis in €" required>
</div>
<div class="form-group">
<label for="r1">
<strong>(Optional)</strong> Randstärke in cm (Wie viel der Pizza ist Rand?)
</label>
<input id="r1" class="form-control" type="number" step="0.1" placeholder="Randstärke in cm">
</div>
<div class="form-group" id="submit-buttons">
<button class="btn btn-primary" type="submit">Preis berechnen</button>
<button id="compare" class="btn btn-tertiary" type="button">Vergleichen +</button>
</div>
</form>
<form id="preis2" class="hidden">
<label>
<h2>Zweite Pizza</h2>
</label>
<div class="form-group">
<label for="d2">Durchmesser in cm:</label>
<input id="d2" class="form-control" type="number" step="0.1" placeholder="Durchmesser in cm" required>
</div>
<div class="form-group">
<label for="p2">
Preis in Euro:
</label>
<input id="p2" class="form-control" type="number" step="0.1" placeholder="Preis in €" required>
</div>
<div class="form-group">
<label for="r2">
<strong>(Optional)</strong> Randstärke in cm (Wie viel der Pizza ist Rand?)
</label>
<input id="r2" class="form-control" type="number" step="0.1" placeholder="Randstärke in cm">
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Preis berechnen</button>
<button id="hide" class="btn btn-tertiary btn-hide" type="button">Verbergen -</button>
</div>
</form>
<div id="rec" class="alert alert-info hidden">
</div>
<div id="result" class="hidden">
<table class="table table-striped table-responsive-sm">
<thead>
<tr>
<th>
(~˘▾˘)~
</th>
<th id="pizza-head-1">
Pizza
</th>
<th id="pizza-head-2" class="hidden">
Pizza 2
</th>
</tr>
</thead>
<tbody>
<tr>
<th>
Flächeninhalt<span class="Rand"> inklusive Rand</span>:
</th>
<td id="flächeninhalt1">
</td>
<td id="flächeninhalt2">
</td>
</tr>
<tr class="Rand">
<th>
Flächeninhalt ohne Rand (nur Pizzabelag):
</th>
<td id="ohneRand1">
</td>
<td id="ohneRand2">
</td>
</tr>
<tr class="Rand">
<th>
Flächeninhalt des Randes (ohne Belag!):
</th>
<td id="nurRand1">
</td>
<td id="nurRand2">
</td>
</tr>
<tr class="Rand">
<th>
➔ Verhältnis Rand zu Belag (je höher, desto besser):
</th>
<td id="verhältnis1">
</td>
<td id="verhältnis2">
</td>
</tr>
<tr>
<th>
➔ Wie viel Pizza-cm² pro Euro (inklusive Rand):
</th>
<td id="kostenVerhältnisMitRand1">
</td>
<td id="kostenVerhältnisMitRand2">
</td>
</tr>
<tr class="Rand">
<th>
➔ Wie viel Pizza-cm² pro Euro (nur Belag):
</th>
<td id="kostenVerhältnisOhneRand1">
</td>
<td id="kostenVerhältnisOhneRand2">
</td>
</tr>
<tr>
<th>
Anteilige Kosten nur für den Pizzabelag:
</th>
<td id="kostenOhneRand1">
</td>
<td id="kostenOhneRand2">
</td>
</tr>
<tr class="Rand">
<th>
Anteilige Kosten nur für den Rand:
</th>
<td id="kostenNurRand1">
</td>
<td id="kostenNurRand2">
</td>
</tr>
</tbody>
</table>
<div id="keinenRandAlert" class="hidden alert" style="padding-left: 0;">
<em>Für genauere Angaben gib einen geschätzen Rand an.</em>
</div>
</div>
<br>
<span id="pizza-wrap" class="hidden">
<p>Ungefähre Darstellung der Pizzagröße <a href="#disclaimer">*</a></p>
<div id="pizza1" class="show-pizza"></div>
<div id="pizza2" class="show-pizza hidden"></div>
<p id="disclaimer"><strong>* Warnung: Sehr ungenau! Hängt von eurem Bildschirm ab und schwankt sogar um mehrere Centimeter!</strong></p>
</span>
</div>
<script>
var hatKeinenRand = true;
var bestRatioMitRand = [];
var bestRatio = [];
var rec = "";
function calc(id) {
d = document.getElementById('d' + id).value.replace(",", ".");
p = document.getElementById('p' + id).value.replace(",", ".");
r = document.getElementById('r' + id).value.replace(",", ".");
f = ( Math.PI * Math.pow((d/2),2) );
fr = ( Math.PI * Math.pow((d-r)/2,2) );
frpp = (( Math.PI * Math.pow((d)/2,2) ) - ( Math.PI * Math.pow((d-r)/2,2) ));
v = fr / frpp;
fp = f / p;
frp = fr / p;
pf = p / f;
fpr = pf * fr;
fprpp = pf * frpp;
document.getElementById('flächeninhalt' + id).innerHTML = f.toFixed(2) + " cm²";
document.getElementById('ohneRand' + id).innerHTML = fr.toFixed(2) + " cm²";
document.getElementById('nurRand' + id).innerHTML = frpp.toFixed(2) + " cm²";
document.getElementById('verhältnis' + id).innerHTML = "1 : " + v.toFixed(2);
bestRatio.push(v.toFixed(2));
document.getElementById('kostenVerhältnisMitRand' + id).innerHTML = fp.toFixed(2) + " <math><mfrac><mi>cm²</mi><mi>€</mi></math><!-- <br><br> (entspricht " + pf.toFixed(2) + " <math><mfrac><mi>€</mi><mi>cm²</mi></math>)-->";
bestRatioMitRand.push(fp.toFixed(2));
document.getElementById('kostenVerhältnisOhneRand' + id).innerHTML = frp.toFixed(2) + " <math><mfrac><mi>cm²</mi><mi>€</mi></math><!-- <br><br> (entspricht " + pf.toFixed(2) + " <math><mfrac><mi>€</mi><mi>cm²</mi></math>)-->";
document.getElementById('kostenOhneRand' + id).innerHTML = fpr.toFixed(2) + " €";
document.getElementById('kostenNurRand' + id).innerHTML = fprpp.toFixed(2) + " €";
document.getElementById('pizza' + id).style.width = d + "cm";
document.getElementById('pizza' + id).style.height= d + "cm";
if ( r ) {
document.getElementById('pizza' + id).style.border= r + "cm solid rgb(230, 219, 128)";
} else {
document.getElementById('pizza' + id).style.border = 0;
}
document.body.style.zoom = 1.0;
if ( 0 != r ) {
hatKeinenRand = false;
}
};
function clicked(both = false) {
document.getElementById('result').classList.remove("hidden");
document.getElementById('pizza-wrap').classList.remove("hidden");
calc("1");
if( both ) {
calc("2");
}
if ( hatKeinenRand ) {
// Keinen Rand angegeben, muss also auch nicht angezeigt werden
document.querySelectorAll('.Rand').forEach(function(item) {
item.classList.add('hidden');
});
} else {
// Zeige auch die Ergebnisse, die den Rand berücksichtigen
document.querySelectorAll('.Rand').forEach(function(item) {
item.classList.remove('hidden');
});
}
if ( bestRatioMitRand.length > 1 && bestRatioMitRand[0] != bestRatioMitRand[1] ) {
if ( bestRatioMitRand[0] > bestRatioMitRand[1] ) {
rec = "Das beste Preis-Leistungs-Verhältnis hat <strong>Pizza 1</strong>.";
} else {
rec = "Das beste Preis-Leistungs-Verhältnis hat <strong>Pizza 2</strong>.";
}
if ( ! hatKeinenRand && bestRatio[0] != bestRatio[1] ) {
if ( bestRatio[0] > bestRatio[1] ) {
rec = rec + " Das beste Verhältnis zwischen Rand und Belag hat <strong>Pizza 1</strong>.";
} else {
rec = rec + " Das beste Verhältnis zwischen Rand und Belag hat <strong>Pizza 2</strong>.";
}
}
}
if ( rec ) {
// Zeig Empfehlung an
document.getElementById('rec').classList.remove("hidden");
document.getElementById('rec').innerHTML = rec;
// Scrolle zur korrekten Stelle
document.getElementById('rec').scrollIntoView({
behavior: 'smooth'
});
} else {
// Scrolle zur korrekten Stelle, wenn keine Rec angezeigt wird
document.getElementById('result').scrollIntoView({
behavior: 'smooth'
});
}
if ( hatKeinenRand ) {
document.getElementById('keinenRandAlert').classList.remove("hidden");
} else {
document.getElementById('keinenRandAlert').classList.add("hidden");
}
// back to default
bestRatio = [];
bestRatioMitRand = [];
hatKeinenRand = true;
};
window.addEventListener("load",function() {
document.getElementById('preis').addEventListener("submit",function(e) {
e.preventDefault(); // before the code
clicked();
});
document.getElementById('compare').addEventListener("click", function(e){
document.getElementById('preis2').classList.remove("hidden");
document.getElementById('pizza-label-1').classList.remove("hidden");
document.getElementById('submit-buttons').classList.add("hidden");
});
document.getElementById('hide').addEventListener("click", function(e){
document.getElementById('preis2').classList.add("hidden");
document.getElementById('pizza-label-1').classList.add("hidden");
document.getElementById('submit-buttons').classList.remove("hidden");
});
document.getElementById('preis2').addEventListener("submit",function(e) {
e.preventDefault(); // before the code
document.getElementById('pizza-head-1').innerHTML = "Pizza 1";
document.getElementById('pizza-head-2').classList.remove("hidden");
document.getElementById('pizza2').classList.remove("hidden");
clicked(true);
});
});
if ('serviceWorker' in navigator){
navigator.serviceWorker.register('serviceworker.js').then(function(registration){
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err){
console.log('ServiceWorker registration failed: ', err);
});
}
</script>
</body>
</html>
|