-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (30 loc) · 1.36 KB
/
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
31
32
33
34
35
36
37
38
function calcular() {
var notaAprov = 6;
var nome = document.getElementById("nome").value;
var n1 = parseInt(document.getElementById("primeiraNota").value);
var n2 = parseInt(document.getElementById("segundaNota").value);
var n3 = parseInt(document.getElementById("terceiraNota").value);
var n4 = parseInt(document.getElementById("quartaNota").value);
var media = ((n1 + n2 + n3 + n4) / 4).toFixed(2);
var resultado;
if (media >= notaAprov) {
resultado = `<div class="aprovado">${nome} Sua Media foi: ${media}<p>Parabéns, você foi aprovado!</p></div>`;
} else {
resultado = `<div class="reprovado">${nome} Sua Media foi: ${media}<p>Que pena, voce foi reprovado..."</p></div>`;
}
if (media == "NaN") {
alert("Ops! você deve selecionar as notas para continuar!");
} else if (nome == '') {
alert("Ops! você não digitou seu nome!");
} else {
document.getElementById("resultado").innerHTML = resultado;
}
}
function limpar() {
document.getElementById("primeiraNota").selectedIndex = 0;
document.getElementById("segundaNota").selectedIndex = 0;
document.getElementById("terceiraNota").selectedIndex = 0;
document.getElementById("quartaNota").selectedIndex = 0;
document.getElementById("resultado").innerHTML = '';
document.getElementById("nome").value = '';
}