Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get user input in javascript

var name = window.prompt("What is your name");
document.write("Hello " + name);
Comment

how to get user input in javascrip

//using npm module
/* 
npm install prompt-sync
# or
yarn add prompt-sync

*/

const prompt = require('prompt-sync')();

const input = prompt('What is your name? ');

console.log(`Oh, so your name is ${input}`);

//* or using readline

const readline = require('readline');

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

rl.question('What is your name? ', function (answer) {
  console.log(`Oh, so your name is ${answer}`);
  console.log('Closing the interface');
  rl.close();
});

//* for brouser input

const input1 = prompt();

const input2 = prompt("What's your name?");
alert(`Your name is ${input}`);

const input3 = prompt('Please enter your age:');
alert(`You are ${input} years old`);
Comment

user input in js

var username = prompt("What is your name?");
Comment

how to get a user input in js

Copyvar name = window.prompt("Enter your name: ");
alert("Your name is " + name);
Comment

PREVIOUS NEXT
Code Example
Javascript :: sorting in javascript 
Javascript :: gesture handling with react native expo 
Javascript :: usereducer example 
Javascript :: jquery get 2 hours frmo now 
Javascript :: create url with query parameters javascript 
Javascript :: what is JSON TREE 
Javascript :: Material-ui add comment icon 
Javascript :: Iteration over JS object 
Javascript :: cart page url in shopify 
Javascript :: begins_with node js AWS dynamodb sort key 
Javascript :: react webpack.config.js example 
Javascript :: Install popper js v2 
Javascript :: repeat an array multiple times in js 
Javascript :: script tag inside react component 
Javascript :: leap year function javascript 
Javascript :: get ip address javascript 
Javascript :: fetch get request 
Javascript :: jquery datatime 
Javascript :: usecallback vs usememo 
Javascript :: javascript range of integers 
Javascript :: generate random special characters javascript 
Javascript :: npm run build serve 
Javascript :: mongoBD increment 
Javascript :: editting collection in firebase firestore 
Javascript :: find my url in nodejs 
Javascript :: java parse json 
Javascript :: javascript split string by multiple characters 
Javascript :: check if number appears odd number of times in array javascript 
Javascript :: render XML in node 
Javascript :: moment is date equals 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =