Lecture 1 JavaScript
Lecture 1 JavaScript
Lecture-1
Intro
• JavaScript was created in 1995 by Brendan Eich,
an engineer at Netscape.
• It is a case sensitive language.
• It can be used in body and head.
• It is similar to c language.
• It has data type ( number, string, Boolean,
Symbol, object (function, array, date, RegExp),
null, undefined
Bismillah
• Let's start with a traditional Bismillah JavaScript!.
<HTML>
<HEAD> <TITLE></TITLE>
<SCRIPT language="javascript">
function Bismillah( )
{ alert (“Bismillah JavaScript!");
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript : Bismillah( )"> First JavaScript
Prog. </A>
</BODY>
</HTML>
Separate JavaScript File (.js)
<html>
<head> <title> Call the Script-File </title>
<script src="first.js"> </script>
</head>
<body>
This is calling script from stored file having extention .js
<form>
<input type="button" value="Call the JavaScript"
onclick="Bismillah()"> </input>
</form> </body> </html>
• javaScript is free format language. No need to
define variables but
• Var can be used to define variables
– Var name=“asad”
• parseInt(): to convert string to
integer.(string,base-to-convert)
– parseInt("123", 10); // 123 parseInt("010", 10); //
10
prompt
<html>
<head> <title> Test Program </title>
<script language="JavaScript">
function GetMyData( )
{ nm= prompt("Enter Your Name:","");
rno= prompt("Enter Your Roll No:","");
alert("The Name of Roll No "+ rno +" is: "+ nm );}
</script>
</head>
<body>
<a href="javascript:GetMyData( )">My Bio Data</a>
</body>
</html>
Exercise:
• Make a web page and insert these three images...
• Make it so that as you click on each number, an
alert box pops up and says "You clicked on 1"
(or 2, or 3).
• Relational Operators:
– <, > , <= , >=, == , !=
• Logical Operators:
– && , || , !
Maths
<html>
<head> <title> Tested Program </title>
<script language="JavaScript">
function Mul()
{ fno=prompt("Enter First No : ","");
sno=prompt("Enter Sec. No : ","");
m = fno * sno;
alert("The Multiplication of " + fno + " and " + sno + " = " + m ); }
function Add()
{ fno=prompt("Enter First No : ","");
sno=prompt("Enter Sec. No : ","");
sum = (fno * 1) + (sno * 1);
alert("The Sum of " + fno + " and " + sno + " = " + sum ); }
</script> </head>
<body>
<h1 align=center> My JavaScript Calculator <h1>
<form>
<input type=button value="Multiplication" onclick="Mul()">
<input type=button value=“ + " onclick="Add()">
</form> </body> </html>
Exercise
• Add the more Buttons for the following
operations and display the result in required
format:
– Operators : /(Div) , % ( remainder ) , --- (minus)