I have tried in vs code and guvi ide platform, there are correct result from both platforms, but I have error from code kata platform.
Question:
Write a code get an integer number as input and print the odd and even digits of the number separately.
Input Description:
A single line containing an integer.
Output Description:
Print the even and odd integers of the integer in a separate line.
Sample Input :
1234
Sample Output :
2 4
1 3
I tried program answer:
// Getting input via STDIN
const readline = require("readline");
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
// console.log('entered data is:', data);
// console.log(userInput);
});
inp.on("close", () => {
//start-here
//Your code goes here … replace the below line with your code logic
let N = userInput[0];
//console.log(N);
let arr = [];
for (i=0; i<=N.length-1; i++){
arr.push(N[i]);
}
//console.log(arr);
//console.log(arr.length);
let even = [];
let odd = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
even += arr[i] + " ";
} else {
odd += arr[i] + " ";
}
}
console.log(even);
console.log(odd);
//end-here
});
I have error:
