I'm trying to display a table in HTML with 16 cells containing numbers from 1 to 16 in a random order. I am having trouble implementing the part where I need to pop a number from the array. Any help would be greatly appreciated :)
Here's the code I have so far:
"use strict";
let numArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let shuffled = shuffleArr(numArr);
function shuffleArr(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
console.log(arr);
return arr;
}
function renderTable(arr) {
let strHTML = "";
for (let i = 0; i < arr.length / 2; i++) {
strHTML += "<tr>";
for (let j = 0; j < arr.length / 2; j++) {
strHTML += `<td></td>`;
}
strHTML += "</tr>";
}
let elTable = document.querySelector(".board");
elTable.innerHTML = strHTML;
}