हमें एक JavaScript और HTML प्रोग्राम लिखना है जो उपयोगकर्ता को एक टेक्स्ट इनपुट और बटन प्रदान करता है। जब उपयोगकर्ता इनपुट में कोई मान दर्ज करता है, मान लीजिए 5, और बटन पर क्लिक करता है, तो हमें स्क्रीन पर निम्नलिखित पैटर्न प्रिंट करना चाहिए।
(n = 5 के लिए)
01 01 02 01 02 03 01 02 03 04 01 02 03 04 05
उदाहरण
<html> <head> <title>JavaScript Number Patterns</title> <script type="text/javascript"> const printPattern = () => { const num = document.getElementById("rows").value; for(let m=1; m <= num; m++){ for(let n=1; n <= m; n++){ document.write("0"+n+" "); } document.write("
"); } } </script> </head> <body> <p>Enter the number of rows and press print</p> <input type="number" placeholder="Number of Rows" id="rows"> <button type="button" onclick="printPattern()">Print</button> </body> </html>
आउटपुट
और कंसोल में आउटपुट होगा:
मान दर्ज करने से पहले -

अंतिम परिणाम -
