-1

I want to create a program that gives you random equations and you can decide what the maximum numbers are. When I for example enter 5 and then click ok. it gives me NaN+NaN. I think this means not-a-number. I have tried converting it to a number with number(). BUt that gave me the same output. How can I fix this?

function bee() {
  var text1 = document.getElementById('number').value;
}

function button() {
  var rand1 = Math.floor(Math.random() * text1);
  var rand2 = Math.floor(Math.random() * text1);
  var html = "<input type='text' id='id'> <button onclick=' check() '> check </button>" + Number(rand2) + '+' + Number(rand1);
  document.getElementById('div').innerHTML = html;
  var text1 = document.getElementById('number').value;
  var answer1 = rand1 + '+' + rand2;
  document.write(html)
  return rand1 + rand2;
}

function check() {
  var text11 = document.getElementById('id').value;
  if (answer == text11) {
    document.write('correct!')
  }
}
bee()
<p>maximum number:<input type="text" id="number"></p>
<button onclick="button()"> ok </button>
<div id='div'>
Barmar
  • 596,455
  • 48
  • 393
  • 495
red_panda
  • 335
  • 15

0 Answers0