I am currently on the “Everything Be True” problem in the “Intermediate Algorithm Scripting” section of the JavaScript course. I have written the code below, which works for every check except the two I have included at the end of the code (both returning false when they should return true).
function truthCheck(collection, pre) {
let arr1 = [];
for (let i = 0; i < collection.length; i++) {
arr1.push(collection[i][pre]);
}
let truthConfirm = target => target == true;
return arr1.every(truthConfirm);
}
console.log(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"));
console.log(truthCheck([{"single": "yes"}], "single"));
I entered the code I wrote into the javascript page of pythontutor.com to confirm whether my code is working as intended, and for whatever reason, while the function is indeed handling the value correctly, “male” is returning as false.
I haven’t yet checked if “female” and “yes” also return false, but because they are strings, I assume they’re supposed to return true.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: Everything Be True
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true