Showing
1 changed file
with
20 additions
and
6 deletions
... | @@ -12,7 +12,7 @@ searchForm.addEventListener('submit', function(event){ | ... | @@ -12,7 +12,7 @@ searchForm.addEventListener('submit', function(event){ |
12 | event.preventDefault(); | 12 | event.preventDefault(); |
13 | } | 13 | } |
14 | else{ | 14 | else{ |
15 | - event.preventDefault(); | 15 | + event.preventDefault(); |
16 | searchQuery = event.target.querySelector('input').value; | 16 | searchQuery = event.target.querySelector('input').value; |
17 | fetchAPI(); | 17 | fetchAPI(); |
18 | } | 18 | } |
... | @@ -27,6 +27,9 @@ async function fetchAPI(){ | ... | @@ -27,6 +27,9 @@ async function fetchAPI(){ |
27 | function boxinfo(results){ | 27 | function boxinfo(results){ |
28 | let boxsinfo =''; | 28 | let boxsinfo =''; |
29 | results.map(result => { | 29 | results.map(result => { |
30 | + const object = { | ||
31 | + cal: result.recipe.calories.toFixed(0) | ||
32 | + }; | ||
30 | boxsinfo += | 33 | boxsinfo += |
31 | ` | 34 | ` |
32 | <style> | 35 | <style> |
... | @@ -34,17 +37,17 @@ function boxinfo(results){ | ... | @@ -34,17 +37,17 @@ function boxinfo(results){ |
34 | display:flex; | 37 | display:flex; |
35 | flex-wrap:wrap; | 38 | flex-wrap:wrap; |
36 | margin-left:50px auto; | 39 | margin-left:50px auto; |
37 | - } | 40 | + } |
38 | .container{ | 41 | .container{ |
39 | display:flex; | 42 | display:flex; |
40 | flex-wrap:wrap; | 43 | flex-wrap:wrap; |
41 | margin-left:50px auto; | 44 | margin-left:50px auto; |
42 | 45 | ||
43 | - } | 46 | + } |
44 | <!--검색결과사진,레시피정보 모두 검색창 옆으로 가게하는거까지는 되었고 2열씩 정렬하려 했는데 2열 정렬 부분이 미완성. 우선 사진 옆으로 정보만 수평으로 뜸--> | 47 | <!--검색결과사진,레시피정보 모두 검색창 옆으로 가게하는거까지는 되었고 2열씩 정렬하려 했는데 2열 정렬 부분이 미완성. 우선 사진 옆으로 정보만 수평으로 뜸--> |
45 | <!--검색결과 뜰 시에 검색창 위치가 바뀌는 문제 있음--> | 48 | <!--검색결과 뜰 시에 검색창 위치가 바뀌는 문제 있음--> |
46 | 49 | ||
47 | - | 50 | + |
48 | </style> | 51 | </style> |
49 | <div class="item"> | 52 | <div class="item"> |
50 | <img src="${result.recipe.image}" alt=""> | 53 | <img src="${result.recipe.image}" alt=""> |
... | @@ -52,9 +55,20 @@ function boxinfo(results){ | ... | @@ -52,9 +55,20 @@ function boxinfo(results){ |
52 | <h1 class="title">${result.recipe.label}</h1> | 55 | <h1 class="title">${result.recipe.label}</h1> |
53 | <a href="${result.recipe.url}" target="_blank">View Recipe</a> | 56 | <a href="${result.recipe.url}" target="_blank">View Recipe</a> |
54 | </div> | 57 | </div> |
55 | - <p class="item-data">Calories: ${result.recipe.calories.toFixed(0)}</p> | 58 | + ${(cal => { |
59 | + if (cal >= 2000) { | ||
60 | + return `<p style="color:red">${cal}</p>`; | ||
61 | + } | ||
62 | + else if(cal >= 1000 && cal < 2000){ | ||
63 | + return `<p style="color:yellow">${cal}</p>`; | ||
64 | + } | ||
65 | + else { | ||
66 | + return `<p style="color:green">${cal}</p>`; | ||
67 | + } | ||
68 | + })(object.cal) | ||
69 | + } | ||
56 | </div> | 70 | </div> |
57 | ` | 71 | ` |
58 | }) | 72 | }) |
59 | searchResultDiv.innerHTML = boxsinfo; | 73 | searchResultDiv.innerHTML = boxsinfo; |
60 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
74 | +} | ... | ... |
-
Please register or login to post a comment