-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (26 loc) · 858 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function calcular(){
var a = window.document.getElementById('na')
var b = window.document.getElementById('nb')
var c = window.document.getElementById('nc')
var na = Number(a.value)
var nb = Number(b.value)
var nc = Number(c.value)
var delta = nb * nb - 4 * na * nc
if (na == 0){
window.alert( "o valor de A não pode ser 0")
exit()
} else if (delta < 0) {
window.alert("Sem raízes reais")
res.innerHTML = `Delta = ${delta}`
res1.innerHTML = `Valor de x1 invalido`
res2.innerHTML = `Valor de x2 invalido`
exit()
} else {
const x1 = (-nb + Math.sqrt(delta)) / (2 * na);
const x2 = (-nb - Math.sqrt(delta)) / (2 * na);
res.innerHTML = `Delta = ${delta}`
res1.innerHTML = `Valor de x1 = ${x1}`
res2.innerHTML = `Valor de x2 = ${x2}`
return;
}
}