Intermediate Algorithm Scripting - Everything Be True

It seems to me that I am doing the same thing as Solution 2, but I am getting false for all of my tests. I don’t see the difference.

  **Your code so far**
function truthCheck(collection, pre) {

return collection.every(truthTest); 

function truthTest(test) {
  return test.hasOwnProperty(pre) && !!test.pre;
//Solution 2
function truthCheck(collection, pre) {
return collection.every(function (element) {
  return element.hasOwnProperty(pre) && Boolean(element[pre]);

truthCheck([{name: "Quincy", role: "Founder", isBot: false}, {name: "Naomi", role: "", isBot: false}, {name: "Camperbot", role: "Bot", isBot: true}], "isBot");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Intermediate Algorithm Scripting - Everything Be True

Link to the challenge:

In the above code snippet, the test.pre results in what?

I thought test.pre was interchangeable with test[pre]. Apparently not. Why? It looks like all properties are single words names.

You can only use dot notation (test.pre) when you already know the name of the property. You’re trying to access a property literally named “pre”, but none exist.

test.pre is the same as test["pre"], but quite different from test[pre] (unless the variable pre has the string value "pre", in which case they’re the same).

Wow! I am glad that was the only issue. That was a very good lesson to learn in a forum like this rather than when I am under the gun to get something real done.

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