Interactions in javascript, alert, prompt, confirm

Опубликовано: 27 Июль 2026
на канале: Empyreal
4
0

You can also learn more about programming here:   / usernamejack  

Hello, if you some help with your work or student life then click this link. (If you want to convert your audio file to pdf or want us to narrate your word file, so that you can listen to rather than read it. it will done by a human.) https://linktr.ee/wisethero

Interaction: alert, prompt, confirm
As we’ll be using the browser as our demo environment, let’s see a couple of functions to interact with the user: alert, prompt and confirm.

alert
This one we’ve seen already. It shows a message and waits for the user to press “OK”.

For example:

alert("Hello");
The mini-window with the message is called a modal window. The word “modal” means that the visitor can’t interact with the rest of the page, press other buttons, etc, until they have dealt with the window. In this case – until they press “OK”.

prompt
The function prompt accepts two arguments:

result = prompt(title, [default]);
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.

title
The text to show the visitor.
default
An optional second parameter, the initial value for the input field.
The square brackets in syntax [...]
The square brackets around default in the syntax above denote that the parameter is optional, not required.

The visitor can type something in the prompt input field and press OK. Then we get that text in the result. Or they can cancel the input by pressing Cancel or hitting the Esc key, then we get null as the result.

The call to prompt returns the text from the input field or null if the input was canceled.

For instance:

let age = prompt('How old are you?', 100);

alert(`You are ${age} years old!`); // You are 100 years old!
In IE: always supply a default
The second parameter is optional, but if we don’t supply it, Internet Explorer will insert the text "undefined" into the prompt.

Run this code in Internet Explorer to see:

Java The Complete Reference 11th Edition: https://amzn.to/3pCh9PZ

SignUp For Audible:https://www.amazon.in/dp/B077S5CVBQ/?...

Signup Today:http: //www.fiverr.com/s2/cd10dfd1a0

Join Fiverr Business, (It will Help Our Channel Grow, Please):
https://track.fiverr.com/visit/?bta=2...
Learn something new today:
https://track.fiverr.com/visit/?bta=2...
Grow Your Business Today:
https://track.fiverr.com/visit/?bta=2...