Okay Friends! Today we are going to see another interesting pattern program which is in pure JavaScript.
The output of the below program will be something like this:
Let’s see the script how to print the right angled triangle using pure JavaScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!DOCTYPE html> <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script type="text/javascript"> function printStars() { document.getElementById("result").innerHTML = ''; var limit = document.getElementById("limit").value; for (var i = limit; i >= 1; i--) { var result = ""; for (var j = i; j >= 1; j--) { result += "*" } document.getElementById("result").insertAdjacentHTML('afterend', result+'<br>'); } } </script> </head> <body> <p>Enter the number of lines <input type="number" id="limit" min="0" /> <button onclick="printStars()">Print Stars</button> <div id="result"></div> </body> </html> |
You can see the demo in here: