Build an All-True Property Validator - Build an All-True Property Validator

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

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?

My bad, I read the goal very much wrong !

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.

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” :wink:

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.