forked from terosassi/beer-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.js
68 lines (53 loc) · 1.72 KB
/
custom.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
class Data {
constructor(name, description,image_url,volume,brewers_tips,food_pairing = [],ingredients = [Ingredients]) {
this.name = name;
this.description = description;
this.image_url = image_url;
this.volume = volume;
this.brewers_tips = brewers_tips;
this.food_pairing = food_pairing;
this.ingredients = ingredients;
}
}
class Ingredients{
constructor(name, unit)
{
this.name = name;
this.unit = unit;
}
}
let dataBeer = Data;
var detailss;
var ingredients;
ingredients = document.getElementById('ingredients_div');
detailss = document.getElementById('DetailsDivv');
loadBeerAllDetails();
function loadBeerAllDetails()
{
data = JSON.parse(localStorage.getItem("beer"));
manageData();
let logo = document.getElementById("logo");
let name = document.getElementById("beer_name");
logo.src = data.image_url;
name.innerHTML = data.name;
let Details = document.getElementById("details");
let food_pairing = "";
for (i = 0; i < data.food_pairing.length; i++) {
food_pairing = food_pairing + data.food_pairing[i];
}
let detailsTxt = "Volume: ".bold()+ data.volume + "<br>" +
"Brewers Tips: ".bold()+ data.brewers_tips + "<br>" +
"Food Pairing: ".bold()+ food_pairing + "<br>" +
"Description: ".bold()+ data.description + "<br>";
Details.innerHTML = detailsTxt;
}
function manageData()
{
var table_data = document.getElementById('ingredients_data');
table_data.innerHTML = "";
for (i = 0; i < data.ingredients.length; i++) {
let row = '<tr id= "'+i+'" class="table_row"><td>'+data.ingredients[i].name+' - '+data.ingredients[i].unit+'</td></tr>'
let html = table_data.innerHTML + row;
table_data.innerHTML = html;
}
}