W
W
WarriorKodeK2018-02-11 20:42:55
JavaScript
WarriorKodeK, 2018-02-11 20:42:55

How to display matrix in DOM?

I need to create a 5x5 matrix and output it.
I know how to create it:

function matrixArray(rows,columns){
  var arr = [];
  for(var i=0; i<rows; i++){
    arr[i] = [];
    for(var j=0; j<columns; j++){
      arr[i][j] = Math.floor(Math.random() * 20) + 10;
    }
  }
  return arr;
}
var myMatrix = matrixArray(5,5);

But how to bring it to the HOUSE by type - https://prnt.sc/id94of , something doesn’t really come to mind. Tell me how to do it?
Thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-11
@WarriorKodeK

function createMatrix(rows, cols, min, max) {
  const matrix = [];

  for (let i = 0; i < rows; i++) {
    matrix[i] = [];

    for (let j = 0; j < cols; j++) {
      matrix[i][j] = Math.floor(Math.random() * (max - min + 1)) + min;
    }
  }

  return matrix;
}

document.querySelector('body').insertAdjacentHTML('beforeend', `
  <table>${createMatrix(5, 5, 10, 30).map(n => `
    <tr>${n.map(m => `
      <td>${m}</td>`).join('')}
    </tr>`).join('')}
  </table>
`);

S
Stalker_RED, 2018-02-11
@Stalker_RED

<table>?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question