Mahoue
March 5, 2026, 2:13am
1
Tell us what’s happening:
I am having trouble on test 8. It demands to return true if an empty array is there. The thing is, it’s false if there is an empty string.
Could anyone give me a hint on how I can get this function better ? (if it needs something like arr.something()). It feels like I am missing an important element to better my code on these last labs.
Your code so far
function truthCheck(collection, pre) {
for(let collect in collection){
console.log(collect)
console.log(collection[collect][pre])
if(collection[collect][pre] == ""
|| collection[collect][pre] != collection[collect][pre]
|| !collection[collect].hasOwnProperty(pre)
|| collection[collect][pre] == null){
return false;
}
}
return true
}
console.log(truthCheck([{name: "freeCodeCamp", users: [{name: "Quincy"}, {name: "Naomi"}]}, {name: "Code Radio", users: [{name: "Camperbot"}]}, {name: "", users: []}], "users"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Challenge Information:
Build an All-True Property Validator - Build an All-True Property Validator
sanity
March 5, 2026, 5:12am
2
Why it should it necessarily be false if there’s empty string? Is the name of the attribute containing empty string, the same as the property that should be checked?
Mahoue
March 5, 2026, 6:38am
3
My bad, I read the goal very much wrong !
Mahoue
March 5, 2026, 6:57am
4
Tell us what’s happening:
The empty array is filtered as false when i have the :
|| collection… == null
but i don’t want it to be false, as it’s asked in the 8th test.
I read that an empty array or a null array isnt the same. What am I supposed to do ?
Your code so far
function truthCheck(collection, pre) {
for(let collect in collection){
console.log(collect)
console.log(collection[collect][pre])
if(collection[collect][pre] != collection[collect][pre]
|| !collection[collect].hasOwnProperty(pre)
|| collection[collect][pre] == null
|| collection[collect][pre] == false){
return false;
}
}
return true
}
console.log(truthCheck([{name: "freeCodeCamp", users: [{name: "Quincy"}, {name: "Naomi"}]}, {name: "Code Radio", users: [{name: "Camperbot"}]}, {name: "", users: []}], "users"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Challenge Information:
Build an All-True Property Validator - Build an All-True Property Validator
Your function returns false for the empty array case because it treats [] as falsy, when in JavaScript, empty arrays are actually truthy values.
ILM
March 5, 2026, 9:37am
6
I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates.
Thanks.
1 Like
Insted of use a lot of “||”, why you don’t try to use only one truthy validation? You allready know the “porperty name”
1 Like
system
Closed
April 3, 2026, 8:48pm
8
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.