Answers for "how to print star pattern in javascript"

1

how to print diamond pattern in javascript

<script type="text/javascript">


    for(var i=1;i<=5;i++)
        {
            for(var j=1;j<=i;j++)
                {
                    console.log("*");
                    
                }
            console.log("\n");
        }



</script>
Posted by: Guest on September-03-2020
0

star pattern in javascript

let n = 5; // you can take input from prompt or change the value
let string = "";
// External loop
for (let i = 1; i <= n; i++) {
  // printing spaces
  for (let j = 1; j <= n - i; j++) {
    string += " ";
  }
  // printing star
  for (let k = 0; k < 2 * i - 1; k++) {
    string += "*";
  }
  string += "\n";
}
console.log(string);
Posted by: Guest on June-02-2021

Code answers related to "how to print star pattern in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language