

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Number pattern in JavaScript
We are required to write a JavaScript and HTML program that provides the user with a text input and button. When the user enters any value in the input, say 5, and clicks the button, we should print the following pattern on the screen.
(for n = 5)
01 01 02 01 02 03 01 02 03 04 01 02 03 04 05
Example
The code for this will be −
<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("<br />"); } } </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>
Output
And the output in the console will be −
Before entering values −
Final result −
- Related Questions & Answers
- Program to print number pattern in C
- Zig-Zag pattern in strings in JavaScript?
- The algorithm problem - Backtracing pattern in JavaScript
- PHP program to print the number pattern
- How to understand JavaScript module pattern?
- How to validate a date pattern in JavaScript?
- Pattern pattern() method in Java with examples
- How to search a string for a pattern in JavaScript?
- Check if a number has bits in alternate pattern - Set 1 in C++
- Phyllotaxis pattern in Python?
- Adapter Pattern in C++?
- 132 Pattern in C++
- Word Pattern in C++
- How to print star pattern in JavaScript in a very simple manner?
- Anagram Pattern Search
Advertisements