Finding even or odd numbers I'm looking for critiques to see what I could have done better or different ways I could approach writing a script for finding even or odd numbers. I am new to programming with JavaScript, and programming in general. This is one of the first challenges I wrote for finding even or odd numbers.
    var numList = [];
    while(numList.length &lt; 5){
    numList.push(window.prompt());
    }

    var evenNumbers = [];
    
    numList.forEach(function(element){
        if (element % 2 === 0){ 
            evenNumbers.push(element);
        }
    })
    document.write(evenNumbers);
You can use Array.prototype.filter.
You can read like this: return an array that only has the elements which satisfies the return function expression.
This way, you can avoid instantiating an array and only after this iteration to make the push.


var numList = [];
while(numList.length &lt; 5){
  numList.push(window.prompt());
}

var evenNumbers = numList.filter(function (element) {
  return element % 2 === 0
});
// that's the same that 
// var evenNumbers = numList.filter(element =&gt; element % 2 === 0);

document.write(evenNumbers);



Although, you can use arrow functions, that has a cleaner syntax.