INtroduction to Java script
INtroduction to Java script
Javascript
• It brings your web pages one step closer to how things look inside
your television, where images appear and disappear, text flies in and
out, and content moves around freely inside the screen.
<HTML>
<HEAD>
<TITLE>Login Page </TITLE>
</HEAD>
<BODY>
HTML Text goes here.
<SCRIPT LANGUAGE="JavaScript">
document.write(“WelCome To green
Bank")
</SCRIPT>
</BODY>
</HTML>
• Variables
• Expressions
• Control Structures
• Functions
• Data Types
• (_)
• Are case-sensitive
if (condition) {
statements1
}
else {
statements2
}
• The program first looks for a label matching the value of expression
and then executes the associated statement. If no matching label is
found, the program looks for the optional default statement, and if
found, executes the associated statement. If no default statement is
found, the program continues execution at the statement following the
end of switch.
• The optional break statement associated with each case label
ensures that the program breaks out of switch once the matched
statement is executed and continues execution at the statement
following switch. If break is omitted, the program continues execution
at the next statement within the switch statement itself.
statements
<SCRIPT language="javascript">
var loginstatus;
for(loginstatus=1;loginstatus<=3;loginstatus++){
if(loginstatus==1){
document.writeln(" Status=1 You can be Login As Manager");
}
if(loginstatus==2){
document.writeln(" Status=2 You can be Login As Staff");
}
if(loginstatus==3){
document.writeln(" status=3 You can be Login As Customer");
}
}
</SCRIPT >
22 © 2012 WIPRO LTD | WWW.WIPRO.COM | CONFIDENTIAL
What will this code print ?
<html>
<body>
<script language="JavaScript">
var x,y;
for(x=19;x>0;x--){
for(y=1;y<=x;y++)
document.write(x+" ");
document.write("<BR>");
}
</script>
</body>
</html
do {
statement
} while (condition)
Statement executes once before the condition is checked. If condition
returns true, the statement executes again. At the end of every
execution, the condition is checked. When the condition returns
false, execution stops and control passes to the statement
following do...while.
var count = 0
do {
count++;
num /= 10;
} while (num>1);
document.write(“total digits”+count);
</ SCRIPT >
• If the condition becomes false, the statements within the loop stop executing
and control passes to the statement following the loop. The condition test
occurs before the statements in the loop are executed. If the condition
returns true, the statements are executed and the condition is tested again. If
the condition returns false, execution stops and control is passed to the
statement following while.
while (condition) {
statements
}
the HEAD of a page so that when a user loads the page, the functions
{
var m=(per/100)*amt;
return m;
var amount=50000;
var per=6;
totalbalance= amount+interest(amount,per) ;
document.write(totalbalance);
</script>