Write a program that reads an integer (greater than 0) from the console and flips the digits of the number, using the arithmetic operators // and %, while only printing out the even digits in the flipped order. Make sure that your program works for any number of digits and that the output does not have a newline character at the end.

Respuesta :

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();

});

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.

ACCESS MORE
EDU ACCESS