R
R
Rustam2021-03-28 14:42:10
JavaScript
Rustam, 2021-03-28 14:42:10

Why is the verification function not working?

When checking the answer, it constantly gives out that the answer is "not correct".
Help me find the error in the code please.


<html>
<head></head>
<body>
  <div id="str"></div>
  <div id="str1"></div>
  <input type="text" id="form">
  <input value="Сгенерировать" onclick="gen()" type="button">
  <input value="Проверить" onclick="check()" type="button">
  <script>
  function getRandomInt(max)
  { 
  return Math.floor(Math.random() * Math.floor(max));
  };
  
  var a = getRandomInt(10) + 1;
  var b = getRandomInt(10) + 1;
  var sum = a + b;
  
  function gen()
  {
  document.getElementById("str").innerHTML=a + " + " + b + " = " + "?";
  };
  
  function check()
  {
  if (document.getElementById("form").innerHTML == sum) document.getElementById("str1").innerHTML="ответ верный";
  else document.getElementById("str1").innerHTML="ответ не верный";
  }
  </script>
</body>
</html>


60606b32c7b5a734991129.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2018-04-01
@l_mke

Maybe so

S
Sun_Day, 2021-03-28
@santanaa

Fix On
document.getElementById("form").innerHTML == sum
document.getElementById("form").value == sum

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question