How To Create X Pattern Using Jquery

In this topic,

We are going to see how to create an “x” pattern.

Step-1: include the jQuery link in the <head>..</head>tag on the index.html file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Step-2: Create Html Code in the index.html file.

<p id="demo"></p>

Step-3: Add jQuery code in <script>…</script> tag on index.html.

I have added 2 for loop to star print.

and appended output in the “#demo” div.

<script>
    $(document).ready(function() {
    var text = "";
    for (i = 1; i<=10; i++) {  
      for (j = 0; j<=10; j++) { 
        if (i==j|| j==10-i) {
            text += "*";
        } 
        else {
          text += "&nbsp;";
        }
        }	
      text  +=  "<br>";
    }
        $("#demo").html (text);    
      }); 
</script>

Review the below screenshot

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories