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

339
Views
prompt problem in VS editor or node js editor

When i want to take user input in my code by taking command prompt vs code or node js editor says it is not defined. But as far i know we can take user input in JS by "prompt" .

example :-

function leapYear(year) {
    if ((year %2 == 0) && (year %100 != 0) || (year %400 == 0)) {
        console.log(year + " LeapYear");
    }
    else{
        console.log(year +" Not a LeapYear");
    }
  
}
const year = prompt('Enter a year:');


leapYear(year);

Uncaught ReferenceError: prompt is not defined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes you can get user input from the command line (so using node), use readline:

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = "";

rl.question("input here:\n", function (string) {
    input = string;
    console.log("input that was entered: " + input);
rl.close();

});

It's a bit more hassle than in other languages.

More here: https://www.educative.io/edpresso/how-to-get-user-input-from-command-line-with-javascript

There's a lot more to readline, so here's the official documentation:

https://nodejs.org/api/readline.html

about 4 years ago · Juan Pablo Isaza 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!