Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript prompt

// window.prompt() => Prompt for user input and return the value:
const person = prompt("Please enter your name");

console.log( "Hello " + person + " !" );

// The 2nd argument (optional) holds the default value:
const color = prompt("Enter a color name", "red");
Comment

js window.prompt

// window.prompt(message);
/*
`window.prompt` opens a confirmation dialog with an "Ok"
and "Cancel" button. Upon receiving input, the dialog is
closed and a boolean is returned. `window.prompt` returns
the input string if the "Ok" button was pressed or null
if "Cancel" was pressed.
*/

const user_input = window.prompt("Hello, what language do you code in?");

if (user_input && user_input.trim()) {
	window.alert(user_input + "! Cool!");
} else {
	window.alert("Oh no! You don't seem to have written anything...");
}
/*
Note that this will pause code execution until the
dialog receives input.
*/
Comment

prompt in javascript

let text = prompt("What's your name?");
if (text !== "") {
  alert(`Your name is: ${text}`);
} else {
  alert(`Name cannot be empty`)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if input is valid 
Javascript :: props reactjs link 
Javascript :: console log state object redux 
Javascript :: li key attribute 
Javascript :: select tag onchange 
Javascript :: regex match to first instance 
Javascript :: ajax call too functions.php 
Javascript :: javascript ip 
Javascript :: node js util promisify 
Javascript :: jquery merge objects 
Javascript :: relative width and height image react native 
Javascript :: get DOM node with xpath 
Javascript :: localstorage save array 
Javascript :: ERR_REQUIRE_ESM 
Javascript :: js select disabled 
Javascript :: mouseover javascript 
Javascript :: jquery source disable right click 
Javascript :: javascript integer length 
Javascript :: jquery open image in new tab 
Javascript :: string to ascii javascript 
Javascript :: jQuery UI Sortable, then write order into a database 
Javascript :: link vs uselink in React Router 
Javascript :: implement the remove property function 
Javascript :: nextjs path alias 
Javascript :: compare dates in js 
Javascript :: eslint allow console 
Javascript :: javascript get keycode from char 
Javascript :: remove animation css javascript 
Javascript :: FileReader get filename 
Javascript :: reactjs firebase nested arrays are not supported 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =