它可以工作,但有时当我点击一个按钮时它会停止

时间:2016-10-11 15:39:52

标签: html debugging web

我的代码基本上有效,但是当我单击开始按钮几次时,所以例如我点击开始,出现随机数,然后我输入一个数字,点击fertig,并做几次这些步骤再次。在这几次之后,当我点击它时,开始按钮被“卡住”。所以我点击它,它会下降,但不会再次上升,你明白了吗? : - )

这是HTML:

<!DOCTYPE html>
<html>



 <head>
  <meta charset="utf-8">
  <title>Der Einmaleins - Trainer</title>  
  <link href = "style.css" type = "text/css" rel = "stylesheet">
  <script src = "script1m1.js"></script>
 </head>
 <body>
  <h1>Der Einmaleins - Trainer</h1> 
  <button type="button" onclick = "start();">Start</button> 
  <button type = "button" onclick = "fertig();">Fertig!</button>
  <input id = "erginput" type = "number">

  <label id = "rn1"></label>  
  <label id = "multiplication"></label>
  <label id = "rn2"></label>  
  <br>
  <label id = "feedback"></label>


 </body>

</html> 

这是JS:

var randomnumber1;
var randomnumber2;

function start() {  
  randomnumber1 = getrn();
  randomnumber2 = getrn();
  while(randomnumber1 == 5 || randomnumber2 == 5 ){
     if (randomnumber1 == 5){randomnumber1 = getrn();}
     else{randomnumber2 == getrn();}

}
document.getElementById("rn1").innerHTML = randomnumber1;
document.getElementById("multiplication").innerHTML = "x";
document.getElementById("rn2").innerHTML = randomnumber2;

}

function getrn(){
  var min = 3;
  var max = 10;
  var zufallszahl = Math.floor(Math.random() * (max - min)) + min;
 return zufallszahl;
}

function ergebnispruefen(zahl,faktor1,faktor2){
  var ergebnisrichtig = faktor1 * faktor2;
  if (zahl == ergebnisrichtig){
       document.getElementById("feedback").innerHTML = "Richtig!";
       document.getElementById("feedback").style.color = "Lime";
  }else{
       document.getElementById("feedback").innerHTML = "Falsch,denk  nach!";
     document.getElementById("feedback").style.color = "red";
}

}

function fertig(){
  var ergebnis = document.getElementById("erginput").value;  
  ergebnispruefen(ergebnis,randomnumber1,randomnumber2);

}

console.log(“提前致谢!:-)”);

Ji W

0 个答案:

没有答案