
previous

page 20
next
You'll recall that on Page 8 we always used a red counter in the cell_clicked function.
In the real game, we need to randomly choose a counter from 1 to 9 so we need a random function. I've written one for you so store the following in a file called Random.js.
function Random(n) { return Math.floor(Math.random() * (n) + 1); }
To get a random number between 1 and 9 inclusive you simply say:
var pick=Random(9);
The player will need a counter right at the start so this line will have to come before anything else. So index.html will end up like this:
<html>
<head>
<title>Yahtzee Solitaire</title>
<link rel='stylesheet' href='styles.css'>
<script src='one_row.js'></script>
<script src='Random.js'></script>
<script src='Sort.js'></script>
<script src='worth.js'></script>
<script src='get_cns.js'></script>
<script src='cell_clicked.js'></script>
</head>
<body>
<script>var pick=Random(9);</script>
<div class='row'>
<script>one_row();</script>
</div>
</body>
</html>
<head>
<title>Yahtzee Solitaire</title>
<link rel='stylesheet' href='styles.css'>
<script src='one_row.js'></script>
<script src='Random.js'></script>
<script src='Sort.js'></script>
<script src='worth.js'></script>
<script src='get_cns.js'></script>
<script src='cell_clicked.js'></script>
</head>
<body>
<script>var pick=Random(9);</script>
<div class='row'>
<script>one_row();</script>
</div>
</body>
</html>
previous
next