Galera, no decorrer do curso criei um código que cálcula média do aluno, porém na hora de preencher a média final quando separei o código em funções não apresenta a média corretamenta, onde estou errando?
var botaoAdicionar = document.querySelector("#adicionar-paciente");
botaoAdicionar.addEventListener("click", function(event) {
event.preventDefault();
var form = document.querySelector("#form-adiciona");
//Extraindo informacoes do aluno do form
var aluno = obtemPacienteDoFormulario(form);
var alunoTr = montaTr(aluno);
var tabela = document.querySelector("#tabela-alunos");
tabela.appendChild(alunoTr);
});
function obtemPacienteDoFormulario(form){
var aluno = {
nome: form.nome.value,
turma: form.turma.value,
primeiroBimestre: parseInt (form.primeiroBimestre.value),
segundoBimestre: parseInt (form.segundoBimestre.value),
terceiroBimestre: parseInt (form.terceiroBimestre.value),
quartoBimestre: parseInt (form.quartoBimestre.value),
media: parseInt (calculaMedia(form.primeiroBimestre.value, form.segundoBimestre.value, form.terceiroBimestre.value, form.quartoBimestre.value))
}
return aluno;
}
function montaTr(aluno){
var alunoTr = document.createElement("tr");
var nomeTd = document.createElement("td");
var turmTd = document.createElement("td");
var pBimestre = document.createElement("td");
var sBimestre = document.createElement("td");
var tBimestre = document.createElement("td");
var qBimestre = document.createElement("td");
var mFinal = document.createElement("td");
nomeTd.textContent = aluno.nome;
turmTd.textContent = aluno.turma;
pBimestre.textContent = parseInt (aluno.primeiroBimestre);
sBimestre.textContent = parseInt (aluno.segundoBimestre);
tBimestre.textContent = parseInt (aluno.terceiroBimestre);
qBimestre.textContent = parseInt (aluno.quartoBimestre);
mFinal.textContent = parseInt (aluno.media);
alunoTr.appendChild(nomeTd);
alunoTr.appendChild(turmTd);
alunoTr.appendChild(pBimestre);
alunoTr.appendChild(sBimestre);
alunoTr.appendChild(tBimestre);
alunoTr.appendChild(qBimestre);
alunoTr.appendChild(mFinal);
return alunoTr;
}