Boa tarde, segue o meu código e depois a dúvida:
var addButton = document.querySelector('#adicionar-paciente');
addButton.addEventListener('click', function(event){
event.preventDefault();
var form = document.querySelector('#user-form');
var paciente = getPacient(form);
console.log(paciente);
var pacientTr = document.createElement('tr');
var nameTd = document.createElement('td');
var weightTd = document.createElement('td');
var heightTd = document.createElement('td');
var fatTd = document.createElement('td');
var imcTd = document.createElement('td');
nameTd.textContent = name;
weightTd.textContent = weight;
heightTd.textContent = height;
fatTd.textContent = fat;
imcTd.textContent = calcIMC(weight, height);
pacientTr.appendChild(nameTd);
pacientTr.appendChild(weightTd);
pacientTr.appendChild(heightTd);
pacientTr.appendChild(fatTd);
pacientTr.appendChild(imcTd);
var table = document.querySelector('#tabela-pacientes');
table.appendChild(pacientTr);
})
function getPacient(form){
var pacient = {
name: form.name.value,
weight: form.weight.value,
height: form.height.value,
fat: form.fat.value,
imc: calcIMC(form.weight.value, form.height.value)
}
return pacient;
}
Após essa instrução, no Visual Studio Code, algumas variáveis aparecem com o nome mais apagado, com o erro: "'pacient' is declared but its value is never read.ts(6133)", caso a variável 'pacient' do início possua o mesmo nome que o objeto 'pacient'. Se eu mudo para "paciente", isso é resolvido. Sabe por que isso pode acontecer?
Além disso o navegador apresenta o seguinte erro: "Uncaught TypeError: Cannot read property 'value' of undefined at getPacient (form.js:38) at HTMLButtonElement. (form.js:6)"
Sendo que "value" está escrito da mesma forma como os demais!
Alguém ajuda?