< script type="text/javascript" >
document.write (123);
< /script >
< script type="text/javascript" >
document.write ("ABC");
< /script >
< script type="text/javascript" >
alert (123);
< /script >
< script type="text/javascript" >
alert ("ABC");
More Variable Usage
< script type = "text/javascript">
var message = "First";
alert (message);
var message = "First";
alert (message);
message = "Second";
alert (message);
< /script >
< /script >
< script type = "text/javascript">
var number1 = 2;
var number2 = 8;
var number1 = 2;
var number2 = 8;
var message - (number1 + number2);
alert (message);
< /script >
< /script >
Prompt Box
< script type = "text/javascript" >
prompt ( "Enter your age");
</script>
Prompt Box Usage
<script type = "text/ javascript">
var age = prompt ("Enter your age");
< /script >
// So the age that the user enters will be = to "age"
// alert ("My age is" +age);
// the above line when added will display a pop up box that reads "My age is ____"
Simple but useful Prompt Script
< script type="text/javascript">
var number1= prompt ("Enter number 1");
var number2= prompt ("Enter number 2");
alert (number 1 + number 2);
< /script >
Arrays -storing a bunch of values in a single variable (var)
< script type="text/javascript" >
var names = new Array ("Adrian0", "Bernard1", "Calvin2");
alert (names [1]) ;
< /script >
// "Bernard1" will be shown in the alert box as computer count starting with '0'.
Array - method 2
< script type="text/javascript" >
var names = new Array ( );
names [0] = "Adrian0";
names [1]= "Bernard1";
names [2] = "Calvin2";
alert (names[2]);
< /script>
// "Calvin2" will be shown in the alert box.