I keep encountering this issue
"Cannot read property 'div' of undefined"
This is the snippet in question
function validateData(){
for(let j = 0; j < 13; j++){
if(dataArr[j].data.textContent === resultSet[j].result.div.textContent){
dataArr[j].data.style.display = "block"
dataArr[j].data.classList.add("validate");
setTimeout(function(){dataArr[j].data.classList.remove("validate");},1001)
successCount += 1
document.getElementById("succeedP").innerHTML = `Success: ${successCount}`
}
}
}
The error message points to resultSet[i].div being undefined below is the specific array it references :
let resultSet = [
{
div: document.getElementById("itemOne")
},
{
div: document.getElementById("itemTwo")
},
{
div: document.getElementById("itemThree")
}
]
I'm uncertain about the cause of this issue as I have implemented a similar function successfully in the past. Could this be related to Scope?