HTML and CSS Reference
Sometimes we need to be able to collect data from the user and do something with it. A
simple example is prompting the user for a name and writing the name to the document.
We would store the name in a variable . You probably took a math course at some point
and used x and y as variables in equations as placeholders for values. The same princi-
can change. Robust programming languages like C++ and Java have all kinds of rules
worry about what type of data is contained in a variable.
Are there any tips for creating variable names?
It really is something of an art form, but first of all, you want to create a variable name that
describes the data it contains. The underscore, or uppercase character, can be used for read-
ability to imply more than one word. Do not use other special characters, though. Stick to
names that could be used for a product code:
isn't necessary but it is good programming practice. We can assign data to a variable
using the assignment operator, the equals sign (=). A variable can contain a number or a
string. A string is encapsulated in quotes, and can contain alphabetic characters, spaces,
numbers, and special characters. For instance, a string can be a last name, e-mail
address, street address, product code, or paragraph of information. Let's do a practice
exercise of assigning data to a variable and writing it to the document.
HANDS-ON PRACTICE 14.4
In this Hands-On Practice you will declare a variable, assign string data to it, and write
it to the document.
Open a text editor and type the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">