-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (60 loc) · 1.99 KB
/
index.js
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
var measurements = [
"tsp",
"oz",
"cup",
"lb",
"tbsp",
"a sprinkle of",
"a dash of",
"gal",
"a dusting of",
"slices of",
];
var endOfLetter = ["Love", "xo", "Will you be my valentine?", "<3"];
function addIngredientsFromList(listToAdd) {
ingredientsList = "";
for (let i = 0; i < listToAdd.length; i += 1) {
let howMany = "";
let units = measurements[Math.floor(Math.random() * measurements.length)];
if (units[0] !== "a") {
howMany = `${Math.floor(Math.random() * 8 + 1)} `;
} else if (units === "slices") {
howMany = `${Math.floor(Math.random() * 8 + 2)} `;
}
ingredientsList += `<pre class="tab1">${howMany}${units} ${listToAdd[i]}</pre>`;
}
return ingredientsList;
}
function showRecipe() {
var name = document.getElementById("name").value;
var relationship = document.getElementById("relationship").value;
var descriptor = document.getElementById("descriptor").value;
var personality = Array.from(
document.getElementById("personality").selectedOptions
).map((el) => el.value);
var physical = Array.from(
document.getElementById("physical").selectedOptions
).map((el) => el.value);
var necessary = document.getElementById("necessary").value;
var sender = document.getElementById("sender").value;
var title = `<h2>Recipe for the ${descriptor} ${relationship}<h2>`;
var ingredientsList = "";
var instructions = `<p>Mix it all together, and <i>voila</i>! You have the ${descriptor} ${relationship}, also known as ${name}.</p>`;
var signed = `<p>${
endOfLetter[Math.floor(Math.random() * endOfLetter.length)]
},</p><p>${sender}</p>`;
ingredientsList +=
addIngredientsFromList(personality) +
addIngredientsFromList(physical) +
addIngredientsFromList([necessary]);
var recipeCard = `
<div class="card">
<div class="container">
<div>${title}</div>
<div>${ingredientsList}</div>
<div>${instructions}</div>
<div>${signed}</div>
</div>
</div>`;
display.innerHTML = recipeCard;
}