| 1. |
What are different popup boxes that are available in JavaScript? |
|
Answer» Javascript uses pop-up boxes to display notifications and messages to users. Here are the different types of pop-up boxes in Javascript:
Syntax: alert("Your Alert Text")Example: Running the FOLLOWING script will open an alert box that contains the message: "This is Scaler Academy" along with a confirmation button OK. <script> alert("This is Scaler Academy");</script>
Syntax: confirm("Your query")Example: Upon executing the following script, it will open a confirmation box containing the following text: "Confirm this action" along with a confirmation button and cancellation button. Based on the input provided by the user, this returns a boolean. It will return true if the user clicks to confirm, and false if the user clicks cancel. <script> let bool = confirm("Confirm this action"); console.log(bool);</script>
Syntax: prompt("Your Prompt")Example: Running the following script will open a pop-up box with the message: "Enter your email". There will also be a confirmation button and a cancellation button. <script> let name = prompt("Enter your email"); console.log(name);</script>You'll be able to see your email on the console once you enter some input in the prompt box. |
|