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.
<!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>
Comments