JAVAについて
Posted: 2013年2月05日(火) 16:25
JavaScriptで「サイコロを振る」ボタンを押すとサイコロ画像が乱数によって表示され、そのサイコロの数が大きい方に点数が入るようにしたのですが
点数が入りません。どこが間違っているのでしょうか?
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>DOMによるアニメーション</title>
<script type="text/javascript">
//サイコロ表示用の配列用意
var sai = new Array(6);
sai[1] = "image/sai_1.gif";
sai[2] = "image/sai_2.gif";
sai[3] = "image/sai_3.gif";
sai[4] = "image/sai_4.gif";
sai[5] = "image/sai_5.gif";
sai[6] = "image/sai_6.gif";
var point_com = 0;
var point_you = 0;
//サイコロを振る関数
function diceroll()
{
var rnd1 = Math.floor( Math.random() * 6 ) + 1;
var rnd2 = Math.floor( Math.random() * 6 ) + 1;
document.coni.src = sai[rnd1];
document.youi.src = sai[rnd2];
if( rnd1 > rnd2)
{
point_com = point_com + 1;
document.getElementById("com").value = point_com;
alert("コンピュータの勝ちです!");
}
else if( rnd1 < rnd2)
{
point_you = point_you + 1;
document.getElementById("you").value = point_you;
alert("あなたの勝ちです!");
}
else
{
alert("あいこです。");
}
}
function reset()
{
document.getElementById("you").value = "0";
document.getElementById("com").value = "0";
}
</script>
</head>
<body bgcolor="#FFFFFF">
<h1>2つのサイコロ</h1>
ボタンをクリックすると、2つのサイコロを振ることができます。<br>
コンピュータ<img src="image/sai_6.gif" name="coni"></img>
<img src="image/sai_1.gif" name="youi"></img>あなた
<br><br>
<form>
<p>
<input type="button" id="Dilo" value="サイコロを振る" onclick="diceroll();">
<br><br>
コンピュータの得点:
<input type="text" name="com" value="0"><br>
あなたの得点:
<input type="text" name="you" value="0"><br><br>
<input type="button" id="Res" value="リセット" onclick="reset();">
</p>
</form>
</body>
</html>
点数が入りません。どこが間違っているのでしょうか?
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>DOMによるアニメーション</title>
<script type="text/javascript">
//サイコロ表示用の配列用意
var sai = new Array(6);
sai[1] = "image/sai_1.gif";
sai[2] = "image/sai_2.gif";
sai[3] = "image/sai_3.gif";
sai[4] = "image/sai_4.gif";
sai[5] = "image/sai_5.gif";
sai[6] = "image/sai_6.gif";
var point_com = 0;
var point_you = 0;
//サイコロを振る関数
function diceroll()
{
var rnd1 = Math.floor( Math.random() * 6 ) + 1;
var rnd2 = Math.floor( Math.random() * 6 ) + 1;
document.coni.src = sai[rnd1];
document.youi.src = sai[rnd2];
if( rnd1 > rnd2)
{
point_com = point_com + 1;
document.getElementById("com").value = point_com;
alert("コンピュータの勝ちです!");
}
else if( rnd1 < rnd2)
{
point_you = point_you + 1;
document.getElementById("you").value = point_you;
alert("あなたの勝ちです!");
}
else
{
alert("あいこです。");
}
}
function reset()
{
document.getElementById("you").value = "0";
document.getElementById("com").value = "0";
}
</script>
</head>
<body bgcolor="#FFFFFF">
<h1>2つのサイコロ</h1>
ボタンをクリックすると、2つのサイコロを振ることができます。<br>
コンピュータ<img src="image/sai_6.gif" name="coni"></img>
<img src="image/sai_1.gif" name="youi"></img>あなた
<br><br>
<form>
<p>
<input type="button" id="Dilo" value="サイコロを振る" onclick="diceroll();">
<br><br>
コンピュータの得点:
<input type="text" name="com" value="0"><br>
あなたの得点:
<input type="text" name="you" value="0"><br><br>
<input type="button" id="Res" value="リセット" onclick="reset();">
</p>
</form>
</body>
</html>