← Back to challenges

Even Number Generator

JavaScriptHardarraysconditionsnumbers

Instructions

Create a function that finds all even numbers from 1 to the given number.

Examples

findEvenNums(8) ➞ [2, 4, 6, 8]

findEvenNums(4) ➞ [2, 4]

findEvenNums(2) ➞ [2]

Notes

If there are no even numbers, return an empty array.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Retrieve the Last N Elements