“Console JavaScript d'entrée” Réponses codées

Entrée de console JavaScript

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

readline.question('Who are you?', name => {
  console.log(`Hey there ${name}!`);
  readline.close();
});
Different Dunlin

Console JavaScript d'entrée

const input = prompt("What's your name?"); //optional params
console.log(input); 
Mo Saeid

JavaScript obtient la contribution de la console

const readline = require("readline");

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

Entrée utilisateur de la console JavaScript

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
Gabriele Orlandi

Réponses similaires à “Console JavaScript d'entrée”

Questions similaires à “Console JavaScript d'entrée”

Plus de réponses similaires à “Console JavaScript d'entrée” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code