2018-10-10 18:03:03 -04:00
---
id: 587d7dab367417b2b2512b6e
2021-02-06 04:42:36 +00:00
title: Use the every Method to Check that Every Element in an Array Meets a Criteria
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-05 16:38:04 +08:00
forumTopicId: 301312
2021-01-13 03:31:00 +01:00
dashedName: use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
The `every` method works with arrays to check if *every* element passes a particular test. It returns a Boolean value - `true` if all values meet the criteria, `false` if not.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
For example, the following code would check if every element in the `numbers` array is less than 10:
2020-08-05 16:38:04 +08:00
```js
var numbers = [1, 5, 8, 0, 10, 11];
numbers.every(function(currentValue) {
return currentValue < 10 ;
});
// Returns false
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Use the `every` method inside the `checkPositive` function to check if every element in `arr` is positive. The function should return a Boolean value.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your code should use the `every` method.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/\.every/g));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`checkPositive([1, 2, 3, -4, 5])` should return `false` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.isFalse(checkPositive([1, 2, 3, -4, 5]));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`checkPositive([1, 2, 3, 4, 5])` should return `true` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert.isTrue(checkPositive([1, 2, 3, 4, 5]));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`checkPositive([1, -2, 3, -4, 5])` should return `false` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.isFalse(checkPositive([1, -2, 3, -4, 5]));
2018-10-10 18:03:03 -04:00
```
2020-08-05 16:38:04 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
function checkPositive(arr) {
// Only change code below this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function checkPositive(arr) {
// Only change code below this line
return arr.every(num => num > 0);
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```