Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
a program to print even numbers of an array of numbers using (for…of) and using prompt -sync
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?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

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.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!