Page 73 - Trackpad_V1_Book 8_Flipbook
P. 73
Let us create a web page to calculate the sum of two numbers in JavaScript.
<HTML>
<HEAD>
<TITLE> Statements in JavaScript </TITLE>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
var a = parseInt(prompt("Enter first number: "));
var b = parseInt(prompt("Enter second number: "));
var c;
c = a + b;
document.write("Sum of a and b is: ");
document.write(c);
</SCRIPT>
</BODY>
</HTML>
Save the file with .html extension and open the web page in web browser. You will get the following
output:
SOME MORE PROGRAMS
Program 1. To print your name using JavaScript
Dynamic Web Pages in HTML5 71

