Back to the 2023 paper

Module III: Basics of Web Programming

20237m

Write a JavaScript program to print this pattern:
*
**




Worked SolutionAI Assisted

JavaScript Pattern Program

Required pattern

*
**
***
****
*****

Program

for (let i = 1; i <= 5; i++) {
    let row = "";
    for (let j = 1; j <= i; j++) {
        row += "*";
    }
    console.log(row);
}

Logic

  • The outer loop controls the 5 rows.
  • The inner loop adds i stars to each row.
  • console.log(row) prints each row on a new line.

Output:

*
**
***
****
*****

Similar questions