Data Structure challenge (Everything but true) doesn't pass on a correct solution

The tests of that challenge https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true doesn’t pass on what looks like a correct solution :

function truthCheck(collection, pre) {
  return collection.every(function(element) {
    return element.hasOwnProperty(pre) && Boolean(element.pre);
  });
} 

but passes on this solution :

function truthCheck(collection, pre) {
  return collection.every(function(element) {
    return element.hasOwnProperty(pre) && Boolean(element[pre]);
  });
} 

I was using Chrome as a browser in a ubuntu 20 machine

Tests cases that fail are indeed returning wrong result, so there’s something not right in function.

Take a closer look at the function in every method, check what both parts in the return statement produce and if that’s what is expected.

you can’t use dot notation to access object properties with variables, element.pre is always undefined because the objects do not have a pre property


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).