Obviously, to square a number you first need to draw a square.
.parent { display: inline-flex; flex-direction: column; } .row { display: flex; flex-direction: row; } .cell { width: 1px; height: 1px; background: red; }
function square(n) { const parent = document.createElement('div') parent.classList.add('parent') for (const _x of new Array(n)) { const row = document.createElement('div') row.classList.add('row') for (const _y of new Array(n)) { const cell = document.createElement('div') cell.classList.add('cell') row.appendChild(cell) } parent.appendChild(row) } document.body.appendChild(parent) const rect = parent.getBoundingClientRect() return rect.width * rect.height }
It will only work for non-negative integer values of n.
n
Other than that, it's limited only by your browser's ability to render thousands upon thousands of divs.
div
I was hoping I'd see something like this 😁
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Obviously, to square a number you first need to draw a square.
CSS
JS
Limitations
It will only work for non-negative integer values of
n
.Other than that, it's limited only by your browser's ability to render thousands upon thousands of
div
s.I was hoping I'd see something like this 😁