Loop In javaScript

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loop In javaScript</title>
</head>

<body>
    <h1>javaScript Loop</h1>
    <p id="demo"></p>
    <p id="demo1"></p>
    <h1>hello </h1>

    <script>

        // for loop

        // let i=0;
        // for(i=0; i<10; i++){
        //     console.log(i)
        // }

        // let friends = ["Avengers", "Lost in Space", "Strangers", "Dark", "Chilling Adventure of Sabrina", "Martian", "intastrastailer"]
        // for (let index1 = 0; index1 < friends.length; index1++) {
        //     console.log(friends[index1]);
        //     // console.log(element)
        //     // console.log(friends.length)
        // }
        // let i = 0;
        // while (i<10) {
        //     console.log("12")
        // }
        // let t=""
        // let unmber= 11000;
        // for ( unmber=0 ; unmber<11000; unmber++){
        //     t+=unmber+'<br>'
        //     document.getElementById('demo1').innerHTML= t
        // }


        let outPut = "";
        let cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi", "Farari"]
        for (let carIndex = 0; carIndex < cars.length; carIndex++) {
            outPut += cars[carIndex] + "<br>";

        }
        document.getElementById("demo").innerHTML = outPut;

        // // var output = "";
        // let car = ['audi', 'BMW', 'maruti', 'Toyota', 'Swift', 'i20']
        // for (let index = 0; index < car.length; index++) {
        //     console.log(car[index])

        // }
        // document.getElementById('demo').innerHTML = output;

        // forEach Loop
        // let moves=["Avengers", "Lost in Space", "Strangers", "Dark", "Chilling Adventure of Sabrina", "Martian", "intastrastailer"]
        // moves.forEach(function f(element){
        //     console.log(element)


        //     })




        let moves = ["Avengers", "Lost in Space", "Strangers", "Dark", "Chilling Adventure of Sabrina", "Martian", "intastrastailer"]
        //for off loops
        for (element4 of moves) {
            console.log(element4)
        }


        //  for in loop 
        let student = {
            name: "Nazrul",
            "Roll No": 265,
            Collage: "Damdama Collage"
        }

        for (key in student) {
            console.log(`The ${key} of student is ${student[key]}`)
            // let stu= student[key];
            // console.log(stu)

        }
        //while loop in javaScript
        let a = 0;
        while (a < 10) {
            console.log(`${a} is lees than 10`)
            a++;
        }

        // do while loop in js
        let j = 34;
        do {
            console.log(`${j} is less than 4 and we are inside do while loop`);
            j++;
        } while (j < 4);

    </script>
</body>

</html> 

Comments

Popular posts from this blog

grid-template-areas

css grid 2