Answer:
const stdin = process.openStdin();
const stdout = process.stdout;
const reverse = input => { //checks if input is number
if (isNaN(parseInt(input))) {
stdout.write("Input is not a number");
}
if (parseInt(input) <= 0) {. // checks if no. is positive
stdout.write("Input is not a positive number");
}
let arr = []; // pushing no. in array
input.split("").map(number => {
if (number % 2 == 0) {
arr.push(number);
}
});
console.log(arr.reverse().join("")); // reversing the array
};
stdout.write("Enter a number: ");
let input = null;
stdin.addListener("data", text => {
reverse(text.toString().trim()); //reversing
stdin.pause();
});
Step-by-step explanation:
In this program, we are taking input from the user and checking if it is a number and if it is positive. We will only push even numbers in the array and then reversing the array and showing it on the console.