jeudi 31 janvier 2019

else preceding an else if preceding an if in javascript won't register

Writing code to display the amount of roots in a quadratic function. However it displays the message for the second if condition whether it is satisfied or not. Could anyone tell me what I could change?

function equation() {

  var a=parseInt(document.getElementById("num1").value);
  var b=parseInt(document.getElementById("num2").value);
  var c=parseInt(document.getElementById("num3").value);

var t1 = b*b
  var t2 = 4*a*c


  if (t1>t2) {

    document.getElementById("output").innerHTML="it has 2 distinct roots"

  } else if (t1=t2) {

    document.getElementById("output").innerHTML="its roots are identical"

  } else {

    document.getElementById("output").innerHTML="it has no roots in real numbers"

  }

}

Aucun commentaire:

Enregistrer un commentaire