I have verified that at some point the first if condition is true. Shouldn't the function return true and stop executing? However; in this case even after the first if condition is true the function keeps on executing until the forEach loop is finished and then exits returning false every time. Can someone tell me where the error is?
function checkValid(id){
pressedButtons.forEach(button => {
console.log(`ID: ${id} and Button: ${button}`)
if (id == button+1 || id == button+8 || id == button-1 || id == button-8){
console.log("IM HERE")
return true
}
})
return false
}