Tell us what’s happening:
Please what is wrong with my if…else statement?.
It should return false if emp and arr has an element in common. But it is doing the opposite.
Your code so far
function truthCheck(collection, pre) {
var emp=[];
var arr=["", undefined, null, 0, false, []];
collection.forEach(elem=>{
emp.push(elem[pre])
})
for(let i=0; i<emp.length; i++){
for(let j=0; j<arr.length; j++){
if(emp[i]!==arr[j]){
var result=true
}else if(emp[i]===arr[j]){
var result=false
}
}
}
//console.log(emp)
return result
}
console.log(truthCheck([{"user": "Tinky-Winky"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Linux; U; Android 7.0; TECNO P701 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.181 Mobile Safari/537.36 OPR/54.0.2254.56148
.
Challenge: Everything Be True
Link to the challenge: