Use the every Method to Check that Every Element in an Array Meets a Criteria, Not passing the test

Tell us what’s happening:

Your code so far


function checkPositive(arr) {
  // Add your code below this line
  
  arr.every(function(currentValue) {
    return currentValue > 0;
  })
  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria/

I don’t know why but my code is not passing the test when checkPositive([1, 2, 3, 4, 5]) is called. when I check this on the browser console it works fine. Any help please?

The function should return a boolean, true or false. Right now it just checks all values in the array and then leaves the function.

2 Likes

Exactly right. just add a return before your arr.every... on the same line.

alternatively, you could create an output variable, assign the results of your every() method to it, then return that variable, but that’s a lot more moving parts than you really need.

1 Like

I just realized how dumb I was on that problem, It was a silly mistake to make! Thanks a a lot guys!