我正在制作一个简单的掷骰子,这对我来说似乎是一个不错的第一个项目,并且可以帮助其他人学习 javascript,并且当您掷骰子(带有按钮)时,它应该加到总数中(有一个清除按钮),但它显示的是 NaN。这是我的代码:
<html>
<body>
<script type="text/javascript">
function load()
{
document.getElementById("press").value=" "
var x=0
}
function d6()
{
var x=x+(Math.floor((Math.random() * 6) + 1));
document.getElementById("press").value=(x)
}
load()
</script>
<input type="button" value="Roll d6" onclick="d6()"/>
<input type="text" id="press"/>
</b>
<input type="button" value="Clear" onclick="load()"/>
</body>
</html>
帮助将不胜感激。谢谢!