Splice Pyramid
by trentHarlem
HTML
<h1>
Splice Pyramid
</h1>
<div id='output'>
</div>
CSS
* {
font-family: system-ui;
}
JavaScript
function pyramidEvenNumbers(n) {
let arr = []
let row = []
let count = 1
let output = document.getElementById('output')
document.body.style.textAlign = 'center'
//get the numbers
for (let i = 0; i <= n; i++) {
if (i % 2 == 0) {
arr.push(i)
}
}
console.log(arr.length, 'Even #s between 0 and ', n, arr)
// get the rows
for (let i = 0; i < arr.length; i++) {
let row = arr.splice(0, count)
//let items = arr.splice(0, count)
//row.unshift(items)
output.innerHTML += `${row.join(" ")}<br>`
console.log(row)
console.log(count)
count++
row = [];
}
}
pyramidEvenNumbers(69)
//* 0.27