Tuesday, 19 November 2013

Logical Pattern Question using JavaScript:

Like
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>
        function CallMe() {
            var num = document.getElementById("txtNum").value;

            for (var i = 1; i <= num; i++)
             {
                 for (var j = 1; j <= i; j++)
                {

                   document.write(i+" ");

                }
                document.write("<br/> ");
                }
           
            }
                alert("hi")

    </script>
</head>
<body>
    <input id="txtNum" type="text" />
    <input id="btnSubmit" type="button" value="button" onclick="CallMe()" />
</body>
</html>

No comments:

Post a Comment