Use the every Method to Check that Every Element in an Array Meets a Criteria help

Use the every Method to Check that Every Element in an Array Meets a Criteria help
0

#1

Working fine for false statements but not for true ones…help

function checkPositive(arr) {
  // Add your code below this line
  var positive=arr.every(function(isPositive){
if (isPositive >0){
    return true;
}else{
    return false;
}

  });
  
  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

#2

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

You assign the result of the every call to a variable named positive, but you never return positive, so your function by default returns undefined.


#4

You generate the variable positive but never return it from checkPositive. The returns inside the callback only return from the callback.

Also, your

if (isPositive >0){
    return true;
}else{
    return false;
}

can be simplified to

return isPositive > 0;

#5

Thanks alotttt…it works now