-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (39 loc) · 1.84 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
39
40
41
42
43
44
45
46
47
48
// Carregar histórico ao abrir a página
document.addEventListener("DOMContentLoaded", carregarHistorico);
function calcularMedia() {
const nome = document.getElementById("nome").value.trim();
const disciplina = document.getElementById("disciplina").value;
const nota1 = parseFloat(document.getElementById("nota1").value) || 0;
const nota2 = parseFloat(document.getElementById("nota2").value) || 0;
const nota3 = parseFloat(document.getElementById("nota3").value) || 0;
const nota4 = parseFloat(document.getElementById("nota4").value) || 0;
if (!nome || !disciplina) {
alert("Por favor, preencha o nome e selecione uma disciplina.");
return;
}
const media = (nota1 + nota2 + nota3 + nota4) / 4;
const resultado = document.getElementById("resultado");
const status = media >= 60 ? "Aprovado" : "Reprovado";
resultado.textContent = `Média: ${media.toFixed(2)} - ${status}`;
resultado.style.color = media >= 60 ? "green" : "red";
salvarHistorico(nome, disciplina, media.toFixed(2), status);
carregarHistorico();
}
function salvarHistorico(nome, disciplina, media, status) {
const historico = JSON.parse(localStorage.getItem("historico")) || [];
historico.push({ nome, disciplina, media, status });
localStorage.setItem("historico", JSON.stringify(historico));
}
function carregarHistorico() {
const historico = JSON.parse(localStorage.getItem("historico")) || [];
const lista = document.getElementById("listaHistorico");
lista.innerHTML = "";
historico.forEach((item, index) => {
const li = document.createElement("li");
li.textContent = `Aluno: ${item.nome}, Disciplina: ${item.disciplina}, Média: ${item.media}, Status: ${item.status}`;
lista.appendChild(li);
});
}
function limparFormulario() {
document.getElementById("resultado").textContent = "";
}