User Interactions
This lesson explains the ways to interact with the user via JavaScript.
We'll cover the following...
Entering information
Once you start using variables, you can write programs that exchange information with the user.
During execution, a dialog box pops up, asking for your name.
This is the result of the JavaScript command prompt("Enter your first name:").
Type your name and click OK. You’ll then get a personalized greeting.
The value you entered in the first dialog box has been stored as a string in the variable name. The JavaScript command alert() then triggered the display of the second box, containing the result of the concatenation of the string "Hello, " with the value of the name variable.
Displaying information
Both console.log() (encountered in the previous chapter) and alert() can be used to display information to the user. Unlike alert(), console.log() does not stop program execution and is often a better choice.
console.log()can also display several comma-separated values at once.