xxxxxxxxxx
// 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.
*/
xxxxxxxxxx
<script>
function myFunction() {
let text;
if (confirm("Press a button!") == true) {
text = "You pressed OK!";
} else {
text = "You canceled!";
}
document.getElementById("div1").innerHTML = text;
}
</script>
Check the Mozilla Docs for more details: https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt