Tell us what’s happening:
On the last if statement, when I change the conditions around(falseCount===0 and falseCount>0), the completed Ii had become grey and the other one are ticked. Why is that, if the statement still covers both conditions?
Your code so far
function truthCheck(collection, pre) {
for (let i = 0; i < collection.length; i++) {
for (let key in collection[i]) {
var falseCount=0;
if (collection[i].hasOwnProperty(key)) {
console.log("checking " + JSON.stringify(collection[i]));
if (collection[i][pre]) {
console.log("this is true!");
} else {
console.log("this is false!");
falseCount++;
console.log("falseCount is " + falseCount);
}
}
}
if (falseCount=0) {
return true;
} else {
return false;
}
}
}
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true