Example
2
The script displays a message box with OK button containing "hello
world" message. This message box is typically called "Alert Box".The
Alert Box has a single OK button, on clicking
which the alert box gets closed. The semicolon after each statement is
optional.
<html>
<body>
<script language="javascript">
alert("hello world");
</script>
</body>
</html>
Example
3
Javascript can perform arithmetical operations also like any other
programming language. HTML code cam be embedded within script. The
script below finds the factorial of numbers one to nine. The for loop
syntax is simple and similar to that used in Java or C programming
languages.
<html>
<body>
<script language="javascript">
document.write("<h2>Table of Factorials</h2>");
for(i=0;f=1,i<10;i++,f *= i)
{
document.write(i+" ! = "+f);
document.write("<br>");
}
</script>
</body>
</html>
Go To
Index
|