Answer to Question #302708 in HTML/JavaScript Web Application for chethan

Question #302708

for...of loop

The goal of this coding exam is to quickly get you off the ground with the for...of loop.

Use the below reference image.

https://assets.ccbp.in/frontend/content/dynamic-webapps/ce-3-1-3-for-of-loop-op.png


HTML

<!DOCTYPE html>

<html>


<head></head>


<body>

  <div>

    <h1>Cars</h1>

    <ul id="listContainer"></ul>

  </div>

</body>


</html>


JAVASCRIPT


let carBrands = ["Benz", "Ferrari", "Audi", "BMW"];


Achieve the design using the for...of loop to iterate over an array in the JS prefilled code.












1
Expert's answer
2022-02-28T01:04:20-0500
<!DOCTYPE html>
<html>
<head></head>
<body>
    <div>
        <h1>Cars</h1>
        <ul id="listContainer"></ul>
    </div>
</body>
<script>
    const container = document.querySelector('#listContainer');
    let carBrands = ["Benz", "Ferrari", "Audi", "BMW"];

    carBrands.map((e) => {
        const item = document.createElement("li")
        item.innerHTML = e;
        container.append(item)
    })
</script>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS