JavaScript Program to Display Chess Board

Write a JavaScript program to display chess board.



Source Code
<html>

<head>
    <title>Display Chess Board</title>
    <style>
        .black {
            width: 30px;
            height: 30px;
            background-color: black;
            display: inline-block;
        }
        .white {
            width: 28px;
            height: 28px;
            background-color: white;
            border: black 1px solid;
            display: inline-block;
        }
    </style>
</head>
<body>
<h3>Chess Board</h3>
<script>
    var startWhite = true;
    for(var i=0; i<8; i++) 
    {
        for(var j=0; j<8; j++) 
        {
            if(startWhite)
            {
                if(j%2 == 0)
                    document.write("<div class=\"white\"></div>");

                else
                    document.write("<div class=\"black\"></div>");
            }
            else
            {
                if(j%2 == 0)
                    document.write("<div class=\"black\"></div>");
                else
                    document.write("<div class=\"white\"></div>");
            }
        }
        if(i%2 == 0)
            startWhite = false;
        else
            startWhite = true;
        document.write("<br>");
    }
</script>
</body>
</html>
Output