Friday, 22 November 2013

Logical Pattern Question And Answer in JS

Like:-

    a
   ei
  oua
 eiou
aeiou

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 type="text/javascript">
    function f1(){
        var arr = ['a','e','i','o','u'];
        var inc=0;
        var num=document.getElementById("txtNum").value;
        for (var row = 1; row <= num; row++) {
            for (var space = num-row; space >= 1; space--) {
                document.write("&nbsp;");
            }
            for (var column = 1; column <= row; column++) {
                document.write(arr[inc]);
               
                inc++;
                if (inc == 5) {
                    inc = 0;
                }

            }
            document.write("<br/>")
       
        }
        }
        alert("hi");
    </script>
</head>
<body>
<input type="text" id="txtNum" />
<br />
<input type="button" value="Button" onclick="f1()" />

</body>
</html>

No comments:

Post a Comment