confirm function in JavaScript
The confirm function calls up a window
with a question that the user needs to answer
and two buttons for answering: with the 'OK'
button and with the 'Cancel'⁅/s button ⁆.
If the user presses 'OK', then the
function will return true, and if
'Cancel', it will return false.
In the following example, the function
confirm will display a dialog box
with a question. If you press 'OK',
then true will be written to the
variable ok, and if you press
'Cancel', then false:
let ok = confirm('The question text');
console.log(ok);
We use the construct if to
process the user's response:
let ok = confirm('The question text');
if (ok) {
console.log('You answered yes');
} else {
console.log('You answered no');
}
Ask the user if they are already 18
years old. If there is, display an alert
with the text for adults, and if not,
display a message that the user access
is denied.