Javascript Level 1- Basic

Output text or numbers on screen


< 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");
< /script >


Variables



< script type = "text/javascript">

var message = "Thank You";
alert (message);

< /script >


<script type = "text/javascript">

var message = 123456789;
alert (message);

< /script >



<script type = "text/javascript">

var message = (10*10+100);
alert (message);

< /script >


More Variable Usage



< script type = "text/javascript">

var message = "First";
alert (message);

message = "Second";
alert (message);
< /script >


< script type = "text/javascript">

var number1 = 2;
var number2 = 8;
var message - (number1 + number2);
alert (message);
< /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.