-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (69 loc) · 2.92 KB
/
script.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
65
66
67
68
69
70
71
72
73
document.getElementById("randomsubmit").addEventListener("click", function (event) {
event.preventDefault();
const url = "https://www.themealdb.com/api/json/v1/1/random.php";
fetch(url)
.then(function (response) {
return response.json();
}).then (function (json) {
console.log(json);
let results = "";
results += "<h2>" + json.meals[0].strMeal + "</h2>";
results += "<img src='" + json.meals[0].strMealThumb + "'/>";
results += "<p>" + json.meals[0].strInstructions + "</p>";
results += "<a href='" + json.meals[0].strYoutube + "'>Youtube Instructions</a>";
document.getElementById("results").innerHTML = results;
document.getElementById("footer").className = "text-center footer1";
})
})
document.getElementById("searchsubmit").addEventListener("click", function (event) {
event.preventDefault();
const value = document.getElementById("searchinput").value;
if (value === "")
return;
console.log(value);
const url = "https://www.themealdb.com/api/json/v1/1/search.php?s=" + value;
fetch(url)
.then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
let results = "";
if (json.meals.length > 1) {
results += "<p>";
for (object in json.meals) {
results += json.meals[object].strMeal + ", ";
}
results += "</p>"
}
else {
results += "<h2>" + json.meals[0].strMeal + "</h2>";
results += "<img class='imgs' src='" + json.meals[0].strMealThumb + "'/>";
results += "<p>" + json.meals[0].strInstructions + "</p>";
results += "<a class='links' href='" + json.meals[0].strYoutube + "'>Youtube Instructions</a>";
document.getElementById("footer").className = "text-center footer1";
}
document.getElementById("results").innerHTML = results;
})
})
document.getElementById("lettersubmit").addEventListener("click", function (event) {
event.preventDefault();
const value = document.getElementById("letterinput").value;
if (value === "")
return;
console.log(value);
const url = "https://www.themealdb.com/api/json/v1/1/search.php?f=" + value;
fetch(url)
.then(function (response) {
return response.json();
}).then(function (json) {
console.log(json);
let results = "";
results += "<p>";
for (object in json.meals) {
results += json.meals[object].strMeal + ", ";
}
results += "</p>"
document.getElementById("results").innerHTML = results;
//document.getElementById("footer").className = "text-center footer1";
})
})