how can i build table by poping a number from shuffled array of 16 numbers and insert it into the HTML?
I Need to render a table to the HTML with 16 cells containing numbers from 1 to 16 in a random order, the question said that you should pop a number from the array and i cant figure it out how to do it, tnx for the help :)
here is my code
"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;
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/K6VGy0w
Comments
Post a Comment