-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
87 lines (80 loc) · 4.08 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="Cake recipe converter" />
<title>Cakeulator - cake recipe converter</title>
<script>
function Cakeulate()
{
var form = document.forms["cakeulator"];
var recipeNumCakes = parseFloat(form["recipe-num-cakes"].value);
var recipeCakeSize = parseFloat(form["recipe-cake-size"].value);
var recipeCakeUnit = form["recipe-cake-unit"].value;
var recipeCakeType = form["recipe-cake-type"].value;
var desiredNumCakes = parseFloat(form["desired-num-cakes"].value);
var desiredCakeSize = parseFloat(form["desired-cake-size"].value);
var desiredCakeUnit = form["desired-cake-unit"].value;
var desiredCakeType = form["desired-cake-type"].value;
recipeCakeSize = recipeCakeUnit == "inch" ? recipeCakeSize : (recipeCakeSize / 2.54);
desiredCakeSize = desiredCakeUnit == "inch" ? desiredCakeSize : (desiredCakeSize / 2.54);
var recipeArea = recipeNumCakes * (recipeCakeType == "round" ? (Math.PI * Math.pow(recipeCakeSize / 2, 2)) : Math.pow(recipeCakeSize, 2));
var desiredArea = desiredNumCakes * (desiredCakeType == "round" ? (Math.PI * Math.pow(desiredCakeSize / 2, 2)) : Math.pow(desiredCakeSize, 2));
var multiple = parseFloat((desiredArea / recipeArea).toPrecision(2));
alert("You need to use " + multiple + " times the recipe!");
}
</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<style>
.form-row
{
align-items: center;
}
@media (max-width: 576px)
{
.form-row>[class*=col-]
{
text-align: center !important;
}
.form-control
{
display: inline-block;
}
}
</style>
</head>
<body>
<div class="container">
<div class="py-4 text-center">
<h1>The Cakeulator</h1>
</div>
<form id="cakeulator" onsubmit="javascript:return false">
<div class="form-row justify-content-center py-1">
<div class="col-sm-2 col-form-label text-right">My recipe makes:</div>
<div class="col-sm-auto"><input type="number" name="recipe-num-cakes" class="form-control" value="1" min="1" step="1" style="width: 4em" /></div>
<div class="col-sm-auto col-form-label">×</div>
<div class="col-sm-auto"><input type="number" name="recipe-cake-size" class="form-control" value="6" min="1" step="1" style="width: 4em" /></div>
<div class="col-sm-auto"><select name="recipe-cake-unit" class="form-control"><option value="inch">inch</option><option value="cm">cm</option></select></div>
<div class="col-sm-auto"><select name="recipe-cake-type" class="form-control"><option value="round">Round</option><option value="square">Square</option></select></div>
<div class="col-sm-1 col-form-label">cakes</div>
</div>
<div class="form-row justify-content-center py-1">
<div class="col-sm-2 col-form-label text-right">I want to make:</div>
<div class="col-sm-auto"><input type="number" name="desired-num-cakes" class="form-control" value="1" min="1" step="1" style="width: 4em" /></div>
<div class="col-sm-auto col-form-label">×</div>
<div class="col-sm-auto"><input type="number" name="desired-cake-size" class="form-control" value="6" min="1" step="1" style="width: 4em" /></div>
<div class="col-sm-auto"><select name="desired-cake-unit" class="form-control"><option value="inch">inch</option><option value="cm">cm</option></select></div>
<div class="col-sm-auto"><select name="desired-cake-type" class="form-control"><option value="round">Round</option><option value="square">Square</option></select></div>
<div class="col-sm-1 col-form-label">cakes</div>
</div>
<div class="form-row justify-content-center py-3">
<div class="col-sm-auto">
<button class="btn btn-primary" value="Cakeulate!" onclick="Cakeulate()">Cakeulate <i class="fas fa-birthday-cake"></i></button>
</div>
</div>
</form>
</div>
</body>
</html>