2018-09-30 22:01:58 +00:00
---
id: 587d7dab367417b2b2512b6e
title: Use the every Method to Check that Every Element in an Array Meets a Criteria
challengeType: 1
2019-08-05 16:17:33 +00:00
forumTopicId: 301312
2018-09-30 22:01:58 +00:00
---
## Description
< section id = 'description' >
The < code > every< / code > method works with arrays to check if < em > every< / em > element passes a particular test. It returns a Boolean value - < code > true< / code > if all values meet the criteria, < code > false< / code > if not.
For example, the following code would check if every element in the < code > numbers< / code > array is less than 10:
2019-05-17 13:20:30 +00:00
```js
var numbers = [1, 5, 8, 0, 10, 11];
numbers.every(function(currentValue) {
return currentValue < 10 ;
});
// Returns false
```
2018-09-30 22:01:58 +00:00
< / section >
## Instructions
< section id = 'instructions' >
Use the < code > every< / code > method inside the < code > checkPositive< / code > function to check if every element in < code > arr< / code > is positive. The function should return a Boolean value.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 13:37:37 +00:00
tests:
- text: Your code should use the < code > every</ code > method.
2019-07-24 08:47:32 +00:00
testString: assert(code.match(/\.every/g));
2018-10-20 18:02:47 +00:00
- text: < code > checkPositive([1, 2, 3, -4, 5])</ code > should return < code > false</ code > .
2019-07-30 13:33:37 +00:00
testString: assert.isFalse(checkPositive([1, 2, 3, -4, 5]));
2018-10-20 18:02:47 +00:00
- text: < code > checkPositive([1, 2, 3, 4, 5])</ code > should return < code > true</ code > .
2019-07-30 13:33:37 +00:00
testString: assert.isTrue(checkPositive([1, 2, 3, 4, 5]));
2018-10-20 18:02:47 +00:00
- text: < code > checkPositive([1, -2, 3, -4, 5])</ code > should return < code > false</ code > .
2019-07-30 13:33:37 +00:00
testString: assert.isFalse(checkPositive([1, -2, 3, -4, 5]));
2018-09-30 22:01:58 +00:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function checkPositive(arr) {
// Add your code below this line
2018-10-08 00:01:53 +00:00
2018-09-30 22:01:58 +00:00
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-04-28 09:01:14 +00:00
function checkPositive(arr) {
// Add your code below this line
return arr.every(num => num > 0);
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
2018-09-30 22:01:58 +00:00
```
2019-07-18 15:24:12 +00:00
2018-09-30 22:01:58 +00:00
< / section >