Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript getting input from console

const readline = require("readline");

rl.question("What is your name? ", function (answer) {
  console.log(`Oh, so your name is ${answer}`);
});
Comment

User Input from Javascript Console

const readline = require("readline");
const ac = new AbortController();
const signal = ac.signal;

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

rl.question("What is your name? ", { signal }, (answer) => {
  console.log(`Oh, so your name is ${answer}`);
  console.log("Closing the console");
  process.exit();
});

signal.addEventListener(
  "abort",
  () => {
    console.log("The name question timed out!");
  },
  { once: true }
);

setTimeout(() => {
  ac.abort();
  process.exit();
}, 10000); // 10 seconds
Comment

how to take input from user in javascript console

there's not input console you can get the value from input in html
ex:
<input type="text" id="inp">
<button onclick="show()"></button>

//javascript
var text = document.getElementById("inp")
function show(){
alert(text.value)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: dictionnary js 
Javascript :: password validation in javascript 
Javascript :: jsx classname 
Javascript :: npm google map react 
Javascript :: vuejs methods 
Javascript :: regex javscript 
Javascript :: getcontext in javascript 
Javascript :: if anagram 
Javascript :: js pow function 
Javascript :: graph data structure in js 
Javascript :: how to reverse sort lines in javascript 
Javascript :: leaflet limit map panning 
Javascript :: How to print even and odd position characters of an array of strings in JavaScript 
Javascript :: javascript declare variables 
Javascript :: javascript function expressions 
Javascript :: javascript rest parameter 
Javascript :: javascript Read Only View of an Object 
Javascript :: what is package.josn file 
Javascript :: ejs split string 
Javascript :: hide loader if datatable data loaded jquery 
Javascript :: nodejs: express, morgan, mongoose package 
Javascript :: change xy scale phaser 
Javascript :: phaser wrap in rectangle 
Javascript :: javascript multiplication without operator 
Javascript :: Opposites attract 
Javascript :: Call this API in order to fetch the user data. API: https://jsonplaceholder.typicode.com/users. 
Javascript :: get elements by class name wildcard 
Javascript :: format numbers js 
Javascript :: schema 
Javascript :: convert html to javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =