forked from Kur0a5h/c1018_hackathon2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
food.js
28 lines (26 loc) · 1.08 KB
/
food.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
class Food {
constructor() {
this.getFoodItem = this.getFoodItem.bind(this);
}
getFoodItem(callback) {
var proteinArray = ["chicken", "fish", "pork", "lamb", "steak", "snacks"];
var protein = proteinArray[Math.floor(Math.random() * proteinArray.length)]; //randomizing through protein array
var foodObject = {
url: "proxies/randombeer.php", //using proxy for CORS policy
method: "get",
dataType: "json",
data: {
url: "http://www.recipepuppy.com/api/",
q: protein
}
}
$.ajax(foodObject).then(function(response) {
var foodSelection = response.results[Math.floor(Math.random() * response.results.length)];
var foodTitle = foodSelection.title;
var ingredients = foodSelection.ingredients;
callback(foodTitle);
$("<h3>").text("Your random recipe is " + foodTitle).appendTo(".recipeTitle");
$("<p>").text("Ingredients: " + ingredients).appendTo(".recipeIngredients");
});
}
}