- alert interaction
- prompt interaction
- Developer tools (console)
Variables. The "prompt" interaction
You can imagine variables as boxes.
You can create a variable and put something in it.
Just like if you have a box and you put something on it.
You can take that out any time you want and use it. Later you can put something else in the box.
Variables are symbolized with “
var” followed by a name of your choice. The name by definition can be anything you want. However, in general, we use names that describe our actions.
Names cannot start with a number and are case sensitive. This means that var name is NOT the same with var Name.
prompt() and the
- With the
prompt()method a box is displayed were the user writes his input.
- With the
document.write()method we can write something on the document.
So, in this case, we will use
prompt() together with
document.write() method to welcome a visitor to our page. Notice that we use double quotes "" for text but not for variables.
<title>Example of prompt()</title>
<h3> Example of prompt()</h3>
visitorName = prompt("What is your name?");
document.write(" Welcome to my page " +visitorName + "!" );
Copy and paste the code into your editor to see the output. Save the file in the folder ''yourNameWEB2JS" as
example05.2.03.html". Next, open the file (
Ctrl+O) in your Chrome.
For more information: https://www.w3schools.com/js/js_variables.asp