. . .
<script. . .>
function rollDice()
{
var d1 = Math.ceil(Math.random() * 6)
var d2 = Math.ceil(Math.random() * 6)
var tot = d1 + d2
document.form1.die1.value = d1
document.form1.die2.value = d2
document.form1.total.value = tot
document.images[0].src="images/dice_" + d1 + ".gif"
document.images[1].src="images/dice_" + d2 + ".gif"
}
</script>
. . .
<body>
<form name="form1">
Die 1 is: <input Type="text" name="die1" SIZE="1">
<IMG src="images/dice_1.gif" ALIGN="center" WIDTH="20" HEIGHT="20" ><br>
Die 2 is: <input Type="text" name="die2" SIZE="1">
<IMG src="images/dice_1.gif" ALIGN="center" WIDTH="20" HEIGHT="20" ><br>
Dice total: <input Type="text" name="total" SIZE="2"> <br>
<input type="button" value="Roll Dice" onClick="rollDice()">
</form>
. . .
function pick_a_number_from_4_to_6()
{
now = new Date();
seed = now.getSeconds();
var random_number = Math.random(seed);
var range = Math.floor(random_number * 3); // val from 4 to 6 (ie., 4, 5, and 6)
range += 4 // this is the low end of the range
document.form2.CPU_Guess.value = range
if(document.form2.CPU_Guess.value == document.form2.User_Guess.value)
{
document.form2.correct.value = parseInt(document.form2.correct.value) + 1
document.form2.Total.value = parseInt(document.form2.Total.value) + 1
document.form2.PctCorrect.value = parseFloat((document.form2.correct.value / document.form2.Total.value)*100).toFixed(2);
}
else
{
document.form2.Total.value = parseInt(document.form2.Total.value) + 1
document.form2.PctCorrect.value = parseFloat((document.form2.correct.value / document.form2.Total.value)*100).toFixed(2);
}
. . .
<form name="form2">
Pick A Number from 4 to 6 <input Type="text" name="User_Guess" SIZE="1">
<br>
Computer guess: <input Type="text" name="CPU_Guess" SIZE="1">
<br>
Total correct: <input Type="text" name="correct" SIZE="2" value=0>
out of: <input Type="text" name="Total" SIZE="2" value=0>
Pct Correct: <input Type="text" name="PctCorrect" SIZE="2" value=0>%<br>
<input type="button" value="Is your guess the same as the Computer"
onClick=" pick_a_number_from_4_to_6()">
</form>