Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
There are three common pop-ups used in Javascript: alert, prompt, and confirm.
Alert
Declaring the window objects is optional (window.alert vs alert).
function ShowAlert()
{
alert("Hello World");
}
Confirm Box
A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user
will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks
"Cancel", the box returns false.
https://www.w3schools.com/jsref/met_win_confirm.asp
function ShowConfirm()
{
var results;
if (confirm("PRESS A BUTTON") === true)
{ results = "You pressed OK!"; }
else
{ results = "You pressed Cancel!"; }
alert(results);
}
Prompt
A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the
user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the
box returns the input value. If the user clicks "Cancel" the box returns null.
function ShowPrompt()
{
var yourName = prompt("What is your name?", "enter name");
if (yourName != null)
{alert("Hello " + yourName + "! How are you today?"); }
}
Line Breaks - To display line breaks inside a popup box, use a back-slash followed by the character n such as \n.
alert("Hello\nHow are you?");