-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
93 lines (92 loc) · 3.13 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Verificar a categoria de cada objeto e executar a funcao
// de acordo com a categoria
for(let i = 0;i < products.length;i++)
{
switch (products[i].category)
{
case "Frutas":
ListarFrutas(products[i].title,products[i].category,products[i].price,products[i].image,products[i].imageDescription)
break;
case "Bebidas":
ListarBebidas(products[i].title,products[i].category,products[i].price,products[i].image,products[i].imageDescription)
break;
case "Higiene":
ListarHigiene(products[i].title,products[i].category,products[i].price,products[i].image,products[i].imageDescription)
break;
}
}
function ListarFrutas(nome,categoria,preco,imagem,alt)
{
const ul = document.querySelectorAll("ul")[0]
const li = document.createElement("li")
const img = document.createElement("img")
const main = document.createElement("main")
const h1 = document.createElement("h1")
const h5 = document.createElement("h5")
const strong = document.createElement("strong")
li.classList.add("product")
img.classList.add("product-img")
main.classList.add("product-main")
h1.classList.add("product-title")
h5.classList.add("product-category")
strong.classList.add("product-price")
img.src = imagem
img.alt = alt
img.title = nome
h1.innerText = nome
h5.innerText = categoria
strong.innerText = preco
main.append(h1,h5,strong)
li.append(img,main)
ul.appendChild(li)
}
function ListarBebidas(nome,categoria,preco,imagem,alt)
{
const ul = document.querySelectorAll("ul")[1]
const li = document.createElement("li")
const img = document.createElement("img")
const main = document.createElement("main")
const h1 = document.createElement("h1")
const h5 = document.createElement("h5")
const strong = document.createElement("strong")
li.classList.add("product")
img.classList.add("product-img")
main.classList.add("product-main")
h1.classList.add("product-title")
h5.classList.add("product-category")
strong.classList.add("product-price")
h1.innerText = nome
h5.innerText = categoria
strong.innerText = preco
img.src = imagem
img.alt = alt
img.title = nome
main.append(h1,h5,strong)
li.append(img,main)
ul.appendChild(li)
}
function ListarHigiene(nome,categoria,preco,imagem,alt)
{
const ul = document.querySelectorAll("ul")[2]
const li = document.createElement("li")
const img = document.createElement("img")
const main = document.createElement("main")
const h1 = document.createElement("h1")
const h5 = document.createElement("h5")
const strong = document.createElement("strong")
li.classList.add("product")
img.classList.add("product-img")
main.classList.add("product-main")
h1.classList.add("product-title")
h5.classList.add("product-category")
strong.classList.add("product-price")
h1.innerText = nome
h5.innerText = categoria
strong.innerText = preco
img.src = imagem
img.alt = alt
img.title = nome
main.append(h1,h5,strong)
li.append(img,main)
ul.appendChild(li)
}