Interaction: alert, prompt, confirm, console.log

Interaction: alert, prompt, confirm, console.log

On this part we will discuss the browser functions alert, prompt and confirm.

alert

Using alert displays a dialog with the given message. Next line of code will not be executed until dialog gets closed (clicking OK button)

The following code will display the Hello word
alert("Hello");

prompt

Using prompt will allow you to retrieve inputs from the user.

First parameter is title of the dialog and second one (optional parameter) is the default value of the textbox.
var userInput = prompt("How old are you?", 30);
console.log(userInput);

confirm

Using confirm will let user to chose either OK or CANCEL button on your question.

var answer = confirm("Would you like to proceed?");
console.log(answer);

The result is true if OK is pressed and false otherwise.

console.log()

This function allows you to log into modern browser console. It helps you to debug your code easily. Very old ones do not support this.

console.log("User ID 1 is being processed");