Functional Programming - Use the every Method to Check that Every Element in an Array Meets a Criteria

Tell us what’s happening:
My current code has curly brackets around my function (with the boolean part), but it doesn’t output the correct answer for one array case. Why is that so?
Your code so far

function checkPositive(arr) {
  // Only change code below this line
  return arr.every(elem => {elem >0})

  // Only change 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/110.0.0.0 Safari/537.36 Edg/110.0.1587.69

Challenge: Functional Programming - Use the every Method to Check that Every Element in an Array Meets a Criteria

Link to the challenge:

You don’t need those curly braces when you’re using arrow function syntax, unless you’re creating a multiline code block, in which case you also need to use the return keyword.
Your code will pass if you remove the curly braces.
(It will also pass if you add the return keyword inside the curly braces, but that’s not good practice in this case).

TLDR: If you use curly braces, you must also use return.

1 Like

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