I was trying to make the Bhaskara formula into functions, but something went wrong and only returns 0
no matter what inputs I put in. Here is the code:
function bhaskaraP(ab, bb, cb) {
var Mb = bb * -1
var b2 = bb * bb
var delta0 = b2 - 4 * ab * cb
var delta = Math.sqrt(delta0)
var rstM = (Mb + delta) / 2 * ab
return rstM
}
function bhaskaraN(ac, bc, cc) {
var Mbc = bc * -1
var b2c = bc * bc
var delta0c = b2c - 4 * ac * cc
var deltac = Math.sqrt(delta0c)
var rstN = (Mbc - deltac) / 2 * ac
return rstN
}
var form = document.getElementById("form")
var a = document.getElementById("a")
var b = document.getElementById("b")
var c = document.getElementById("c")
var ax = a.value
var bx = b.value
var cx = c.value
var bh1 = bhaskaraP(ax, bx, cx)
var bh2 = bhaskaraN(ax, bx, cx)
form.addEventListener('submit', function () {
alert(bh1 + " " + bh2)
})
<div>
<form id="form">
Digite o A: <input id="a" type="number">
<br>
<br>
Digite o B: <input id="b" type="number">
<br>
<br>
Digite o C: <input id="c" type="number">
<br>
<input type="submit">
</form>
</div>