Javascript没有像它应该的那样工作

时间:2018-01-27 07:11:56

标签: javascript html forms

我制作了一个表单,当按下滚动按钮但没有输出时显示不同数量的星星。

<html>
<head>
 <title>Roll a die</title>
</head>

<body>
    <form name="dieForm">
        <input type="text" id="die" readonly="true" size="18">
        <input type="button" value="Roll" onclick="Roll()">
    </form>
<script>
    function Roll(){
        var dieNumber, dieDots, dots;
        dieDots="* ";
        dieNumber=math.round(6*math.random());
        for(dots=2;dots<=dieNumber;dots=dots+1){
          dieDots="* ";
        }
        document.getElementById("die").value=dieDots;
    }
</script>
</body>

2 个答案:

答案 0 :(得分:0)

错误很少。首先它不能math它必须是Math,然后是+=内部循环。这是工作一个:

<head>
<title>Roll a die</title>
</head>

<body>
    <form name="dieForm">

        <input type="text" id="die" readonly="true" size="18">
        <input type="button" value="Roll" onclick="Roll()">
    </form>
<script>
    function Roll(){
      var dieNumber, dieDots, dots;
      dieDots="* ";
      dieNumber=Math.round(6*Math.random());
      for(dots=2;dots<=dieNumber;dots++){
          dieDots+="* ";
      }
      document.getElementById("die").value=dieDots;
    }
</script>
</body>

答案 1 :(得分:0)

enter image description here

你写的数学,应该是数学