Boa tarde!
Ao seguir os passos do primeiro vídeo, quando clico no título aparece a seguinte mensagem: Cannot read property 'addEventListener' of null at main.js:41
O código está da seguinte forma:
var title = document.querySelector('.main-title');
var pacients = document.querySelectorAll(".paciente");
for(i=0; i < pacients.length; i++){
var pacient = pacients[i];
var tdWeight = pacient.querySelector('.info-peso');
var tdHeight = pacient.querySelector('.info-altura');
var tdImc = pacient.querySelector('.info-imc');
var weight = tdWeight.textContent;
var height = tdHeight.textContent;
var imc = weight/(height*height);
var weightTrue = true;
var heightTrue = true;
if(weight <= 0 || weight > 600){
weightTrue = false;
tdImc.textContent = 'Peso inválido';
pacient.classList.add('paciente-invalido');
}
if(height <= 0 || height > 3){
heightTrue = false;
tdImc.textContent = 'Altura inválida';
pacient.classList.add('paciente-invalido');
}
if(weightTrue && heightTrue){
var imc = weight/(height*height);
tdImc.textContent = imc.toFixed(3);
}
}
title.addEventListener("click", showMessage);
function showMessage(){
console.log('Olá! Eu fui clicado!')
}
O que pode estar dando errado?
Grato desde já