-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.js
86 lines (74 loc) · 2.17 KB
/
new.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
let counter = 0
let feeling = "All";
let purpose = "";
let products;
let number;
let recomarray;
fetch("/recipe2.json", {
method: 'POST'
})
.then(response => response.json())
.then(json => {
products = json;
})
.catch(err => { console.log(err) });
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("recommend").addEventListener("click", setSearchOption, false);
});
function setSearchOption() {
feeling = document.getElementById("feeling").value;
purpose = document.getElementById("purpose").value;
recomarray = new Array();
clearimage();
loadimage();
}
function loadimage() {
if(feeling === "sad") {
loadfilter1();
}
else if(feeling === "bad") {
loadfilter2();
}
else {
loadfilter3();
}
}
function loadfilter1() {
for(let d in products) {
if(products[d].RCP_TTL.includes("달콤") || products[d].CKG_IPDC.includes("달콤")) {
if(products[d].CKG_STA_ACTO_NM.includes(purpose)) {
recomarray.push(products[d]);
}
}
}
appendimage(recomarray);
}
function loadfilter2() {
for(let e in products) {
if(products[e].RCP_TTL.includes("매콤") || products[e].CKG_IPDC.includes("매콤")) {
if(products[e].CKG_STA_ACTO_NM.includes(purpose)) {
recomarray.push(products[e]);
}
}
}
appendimage(recomarray);
}
function loadfilter3() {
for(let f in products) {
if(products[f].CKG_STA_ACTO_NM.includes(purpose)) {
recomarray.push(products[f]);
}
}
appendimage(recomarray);
}
function clearimage() {
let image = document.getElementById("results");
while(image.hasChildNodes()) {
image.removeChild(image.firstChild);
}
}
function appendimage(productarray) {
let hnode = document.createElement("h2");
hnode.innerHTML = productarray[Math.floor(Math.random()*(productarray.length - 2))].RCP_TTL;
document.getElementById("results").appendChild(hnode);
}