-
-
Save azamsharp/57b19d609e9031e7e3319a9a78892a8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dishList is a UL element in HTML | |
let dishList = document.getElementById("dishList") | |
// METHOD 1 | |
/* | |
for(let index = 0; index < dishes.length; index++) { | |
let dish = dishes[index] | |
let dishItem = ` | |
<li> | |
<img class="dish-image" src="${dish.imageURL}" /> | |
<b>${dish.title}</b> | |
<p>${dish.description}</p> | |
<b>$${dish.price}</b> | |
</li> | |
` | |
// dishList is UL | |
// insertAdjacentHTML is going to add the HTML to the end of UL | |
dishList.insertAdjacentHTML('beforeend',dishItem) | |
} */ | |
// METHOD 2 (ARRAY HELPERS) | |
// map array helper is also known as transformation operator | |
let dishItems = dishes.map(function(dish) { | |
return `<li> | |
${dish.title} | |
<p>${dish.description}</p> | |
</li>` | |
}) | |
dishList.innerHTML = dishItems.join(" ") | |
console.log(dishItems) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment