Hi everyone, I’ve been reading through the W3School website to learn a bit about scripting recently.
I’ve been wanting to design a 3x3 table that would generate random numbers from 1-9 without repetition. Although I can think of making it work with a series of If statements, maybe coupled with Else statements, I’m sure there is a more efficient way. Might someone shine some light of that?
As for codes, so far, I’ve only made the HTML… the numbers in the grid are just placeholders, they are meant to be changed via JS, rather than be switched around-- unless switching them around is actually a better option.
<html>
<head>
<script type="text/javascript">
</script>
<style type="text/css">
td.grid
{
text-align: center;
}
</style>
</head>
<body>
<p id="txt"> </p>
<table border="1" style="width:100px;">
<tr>
<td id="t1" class="grid">
1
</td>
<td id="t2" class="grid">
2
</td>
<td id="t3" class="grid">
3
</td>
</tr>
<tr>
<td id="t4" class="grid">
4
</td>
<td id="t5" class="grid">
5
</td>
<td id="t6" class="grid">
6
</td>
</tr>
<tr>
<td id="t7" class="grid">
7
</td>
<td id="t8" class="grid">
8
</td>
<td id="t9" class="grid">
9
</td>
</tr>
</body>
</html>