let arr3 = require('prompt-sync')()('val')
let printevn = [];
function evennum(no) {
for (eh of no) {
if (eh % 2 == 0) {
printevn.push(eh);
continue;
}
}
}
evennum(arr3);
console.log(printevn);
When I don't take any value from user and lets say value are 1,2,3,4,5,6,7,8,9,12 my program prints even numbers 2,4,6,8,12 //no error
But when I use npm package known as prompt-sync which allows as to give user values from terminal itself same like prompt in web browser.
let's say the values are 1,2,3,4,5,6,7,8,9,12
my program prints 2,4,6,8,2 //ERROR it doesn't print 12 instead it prints 2 i.e 2nd digit of 12 check the terminal output here
Any suggestions please?
let arr3 = require('prompt-sync')()('val')
let printevn = [];
function evennum(no) {
// console.log(no)
let arr = no.split(',').map(v => parseInt(v));
for (eh of arr) {
if (eh % 2 == 0) {
printevn.push(eh);
continue;
}
}
}
evennum(arr3);
console.log(printevn);
arr3 contains your input as a string. You need to convert the comma-separated string to a number array, Then you can check if it is odd or even.