JavaScript Number Pattern 62

JavaScript Number Pattern 62

Try to print the following number pattern using JavaScript.

Print This Output
1   2   3   4   5   6   7   8   9  10
36  37  38  39  40  41  42  43  44  11
35  64  65  66  67  68  69  70  45  12
34  63  84  85  86  87  88  71  46  13
33  62  83  96  97  98  89  72  47  14
32  61  82  95  100 99  90  73  48  15
31  60  81  94  93  92  91  74  49  16
30  59  80  79  78  77  76  75  50  17
29  58  57  56  55  54  53  52  51  18
28  27  26  25  24  23  22  21  20  19

Source Code

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> div{ display: inline-block; text-align: center; width: 25px; } </style> </head> <body> <script> var a = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]; var i, j = 0, n = 1; var low = 0, high = 9; for(i=0; i<5; i++, low++, high--) { for(j=low; j<=high; j++, n++) a[i][j] = n; for(j=low+1; j<=high; j++, n++) a[j][high] = n; for(j=high-1; j>=low; j--, n++) a[high][j] = n; for(j=high-1; j>low; j--, n++) a[j][low] = n; } document.write("Perfect Square Spiral<br>"); for(i=0; i<10; i++) { document.write("<br>"); for(j=0; j<10; j++) document.write("<div>" + a[i][j] +"</div>"); } document.write("<br>"); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author