Variables are temporary holding areas for information you want to store. For example, in your math classes you have assigned numbers to a variables like so:
x=5
y=4
Therefore, x + y = 9
The JavaScript prompts on this page are doing the same. They are requesting two numbers from the user and assigning the values to two variables. The numbers you entered, in response to the prompts, are stored in variables named 'firstnumber' and 'secondnumber.'
Once variables are stored, they can be manipulated. In this case, 'firstnumber' and 'secondnumber' are multiplied to determine their product. Let's say you entered 5 at the first prompt and 6 at the second prompt. This is what happened:
firstnumber = 5 (The first number variable was set to 5)firstnumber * secondnumber = 30 (the variables were multiplied to determine their product)
We used JavaScript to write the result on this Web page.
The product of and is 0
Here's the code to generate the prompts and to display the product:
<script language="JavaScript" type="text/javascript">
var firstnumber //Create variable to hold first number to multiply
firstnumber = window.prompt("Please enter the first number to multiply.", "");
var secondnumber //Create variable to hold second number to multiply
secondnumber = window.prompt("Please enter the second number to multiply.", "");
//Calculate and display the result
window.document.write ("<p>The product of " + firstnumber + " and " + secondnumber + " is " + (firstnumber * secondnumber) + "<p>");
</script>