Fri Jan 20 2023
Numeric Pyramid
JavaScript422 views
File Name: javascript-numeric-pyramid.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Numeric Pyramid</title>
<style>
#pyramid {
margin-top: 20px;
color: #f00;
}
</style>
<script>
function numPyramid() {
let steps = (document.getElementById('steps').value * 1);
document.getElementById('pyramid').innerHTML = "";
for (let i = 1; i <= steps; i++) {
for (let j = 1; j <= i; j++) {
document.getElementById('pyramid').innerHTML += i;
}
document.getElementById('pyramid').innerHTML += '<br />'
}
}
</script>
</head>
<body>
<h1>Generate Numeric Pyramid</h1>
<input type="text" placeholder="Mention Number of Steps" id="steps" />
<button type="button" onclick="numPyramid()">Generate</button>
<div id="pyramid"></div>
</body>
</html>
Result Screenshot(s)
Author:Geekboots