javascript - Having issue with the “for” statement or maybe confusion on how to correctly implement the statement. -


what i’m trying build math testing app javascript. i’m having issue statement, want add 1 point score every question answered correct. test have set score 0 , userid user input, if user enters correct answer increase 1 keeps increasing 10. there way stop count after first cycle , wait till second cycle , forth till hits 10?

<!doctype html> <html> <head> </head>  <body>  <div id="scoreblock"><span id="score">0</span></div> <input type="text" id="userid"/> <button onclick="begin();">start</button>    <script> function begin(){  var h= document.getelementbyid("score"); var user =document.getelementbyid("userid").value; var test = "5";  for(h=0;h<=10;h++){ if(user==="5"){  document.getelementbyid("score").innerhtml= h;  }else if(!user==="5"){  alert("noting"); }  }//end of while }//end of function </script>  </body> </html> 

in test consider right answer happens when user == 5. 10 times while not changing conditions. it's 10 time right answer.

<script> function begin(){  var user = document.getelementbyid("userid").value; var test = "5"; var correctanswer = 0;  for(var h=0;h<=10;h++){     if(user==="5"){         correctanswer++;     } }  document.getelementbyid("score").innerhtml= correctanswer;  if (correctanswer == 0) {     alert("noting"); } </script> 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -