// 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");
// 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.
*/
let text = prompt("What's your name?");
if (text !== "") {
alert(`Your name is: ${text}`);
} else {
alert(`Name cannot be empty`)
}