I can't seem to figure out what I should be doing here. I've created a code block for testing, that generates a table based off of some random numbers and input from the user(this will come later and is not present in the current code block). The random numbers are generated and stored in variables that are then kept in a two dimensional array.
I've figured out how to generate a simple table using two for loops and document writing, however i would like to format the end result with a border and some interior padding. I cannot figure out to do this.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link href="styles.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway&display=swap&" rel="stylesheet">
<script>
function main() {
var x = 10; // 2 decimals
var b1 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var b2 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var b3 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var b4 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var b5 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var s1 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var s2 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var s3 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var s4 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var s5 = Math.floor(Math.random() * (8 * x - 1 * x) + 1 * x) / (1 * x);
var n1 = "Newman"
var n2 = "Sally"
var mainArr = [
[n1, b1, b2, b3, b4, b5],
[n2, s1, s2, s3, s4, s5]
];
document.write("<table>")
document.write("<tr><td>Employee</td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td>")
for (var i = 0; i < mainArr.length; i++) {
var arrInd = mainArr[i];
document.write("<tr>")
for (var j = 0; j < arrInd.length; j++) {
document.write("<td>" + mainArr[i][j] + "</td>");
}
}
document.write("</table>")
}
</script>
</head>
<body onload="main()">
</body>
</html>
I have looked on Stack already, as-well-as several other sites, and while the information presented seems to make sense, I haven't had luck trying to integrate code from them, into my code. Ex: document.CreateElement("table")
and so forth. It seems like it should work, however as has been the trend with most of my questions on Stack thus far, I think I may be having a hard time understanding the logic of how it works.
tl;dr: I would like help formatting the table generated with the above code, specifically a simple border and some cell interior padding.
Thanks in advance.