윤희찬

Add calories color

...@@ -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>
...@@ -52,7 +55,18 @@ function boxinfo(results){ ...@@ -52,7 +55,18 @@ 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 })
......