Skip to content
TechToolsHQ
NewsReviewsGuidesTech 101Tech SeriesToolsNewsletter
TechToolsHQ

Independent, research-driven tech coverage — breaking news, in-depth reviews, buying guides, and technical tutorials to help you understand and choose with confidence.

Explore
NewsReviewsGuidesTech 101Tech SeriesFree Tools
Legal
About UsOur AuthorsContact UsPrivacy PolicyTerms of ServiceCopyright & DMCAAffiliate DisclosureEditorial PolicyAdvertise With Us

© 2026 TechToolsHQ. All rights reserved.

Tech Series/Data Structures & Algorithms/Pattern Printing Problems in JavaScript: 6 Star & Number Patterns Explained
Data Structures & Algorithms · Part 1 of 1

Pattern Printing Problems in JavaScript: 6 Star & Number Patterns Explained

Six star and number pattern problems, solved — the first part of the Data Structures & Algorithms series.

By Himanshu Bhatt· 1 min read· September 27, 2026

Pattern Printing Problems — Data Structures & Algorithms series hero
Key Takeaways · TL;DR
  • Six star and number pattern problems, solved in JavaScript with nested loops.
  • Each solution is the outer loop picking a row and the inner loop building it.
  • Part 1 of the Data Structures & Algorithms series.
☰ On this page(show)(close)
  • •Pattern 1: N×N star square
  • •Pattern 2: increasing star triangle
  • •Pattern 3: increasing number triangle
  • •Pattern 4: repeated-digit triangle
  • •Pattern 5: decreasing star triangle
  • •Pattern 6: decreasing number triangle
On this page
  • •Pattern 1: N×N star square
  • •Pattern 2: increasing star triangle
  • •Pattern 3: increasing number triangle
  • •Pattern 4: repeated-digit triangle
  • •Pattern 5: decreasing star triangle
  • •Pattern 6: decreasing number triangle
INFO

This is Part 1 of the Data Structures & Algorithms series — six pattern problems solved with nested loops.

Pattern 1: N×N star square

Given an integer N, print the following pattern.

N = 5
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

N = 3
* * *
* * *
* * *
function pattern(n) {
  for (let i = 0; i < n; i++) {
    let str = "";
    for (let j = 0; j < n; j++) {
      str += "* ";
    }
    console.log(str);
  }
}

let n = 5;
pattern(n);

Pattern 2: increasing star triangle

Given an integer N, print the following pattern.

*
* *
* * *
* * * *
* * * * *
function pattern(n) {
  for (let i = 1; i <= n; i++) {
    let stars = "";
    for (let j = 1; j <= i; j++) {
      stars += "* ";
    }
    console.log(stars);
  }
}

let n = 5;
pattern(n);

Pattern 3: increasing number triangle

Given an integer N, print the following pattern.

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
function pattern(n) {
  for (let i = 1; i <= n; i++) {
    let number = "";
    for (let j = 1; j <= i; j++) {
      number += j + " ";
    }
    console.log(number);
  }
}

let n = 5;
pattern(n);

Pattern 4: repeated-digit triangle

Given an integer N, print the following pattern.

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
function pattern(n) {
  for (let i = 1; i <= n; i++) {
    let numberPattern = "";
    for (let j = 1; j <= i; j++) {
      numberPattern += i + " ";
    }
    console.log(numberPattern);
  }
}

let n = 5;
pattern(n);

Pattern 5: decreasing star triangle

Given an integer N, print the following pattern.

* * * * *
* * * * 
* * * 
* *
*
function pattern(n) {
  for (let i = n; i >= 1; i--) {
    let stars = "";
    for (let j = 1; j <= i; j++) {
      stars += "* ";
    }
    console.log(stars);
  }
}

let n = 5;
pattern(n);

Pattern 6: decreasing number triangle

Given an integer N, print the following pattern.

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
function pattern(n) {
  for (let i = n; i >= 1; i--) {
    let numbers = "";
    for (let j = 1; j <= i; j++) {
      numbers += j + " ";
    }
    console.log(numbers);
  }
}

let n = 5;
pattern(n);
Share
Series: Data Structures & Algorithms

Part 1 — Pattern Printing Problems in JavaScript: 6 Star & Number Patterns Explained

Part 1 of 1
First episode in this series.
Latest episode in this series.

Enjoying the Data Structures & Algorithms series?

TechToolsHQ is an independent, reader-supported tech platform. If this article saved you time, solved a tough problem, or helped you learn a new skill, consider supporting our work. Your support helps us keep our in-depth series 100% free and updated for everyone.

100% optional · Reader supported · Independent researchSupport our work

Don't miss the next deep-dive

Weekly breakdowns of the tools students and builders actually use.

No spam·Unsubscribe any time·Privacy-first