samedi 25 novembre 2017

My if statement gives me the wrong output

window.onload = start;


function start() {

  document.getElementById("kalk").onclick = find;
  find(1, 9999);
}

function find(min, max) {
  var factor = document.getElementById("tall").value;
  var factor2 = document.getElementById("tall2").value;

  var x = factor * factor2;

  document.getElementById("utskrift").innerHTML = x;

  if (x >= min && x <= max) {
    document.getElementById("msg").innerHTML = "Number is in interval."
  } else {
    document.getElementById("msg").innerHTML = "Number is not in interval."
  }
}
<h2>Gang to tall</h2>

T1 <input type="number" id="tall" /> T2 <input type="number" id="tall2" />

<button id="kalk">Finn tall i intervall</button> Sum: <span id="utskrift"></span>

<p id="msg"></p>

So by reading this code.. what Im trying to do is have two inputs where i multiply the numbers typed in them. In my "Find()" Parameter i have two arguments that says the numbers should be between 1-9999. In my "function find" i called these arguments min and max. Further down the code Im asking if the output is between these numbers are between min and max give "Number is in interval". The problem is that when i even when the numbers are in these arguments i get my else statement. Is there anyway to fix this or put an input felt in the parameter?

Thanks

Aucun commentaire:

Enregistrer un commentaire