Q) What is DHTML? What are the features of DHTML?
DHTML stands for Dynamic HTML. DHTML is neither a language like HTML,
JavaScript etc. nor a web standard. It is just a combination of HTML,
JavaScript and CSS. It just uses these languages features to build dynamic web
pages. DHTML is a feature of Netscape Communicator 4.0, and Microsoft Internet
Explorer 4.0 and 5.0 and is entirely a "client-side" technology.
Features of DHTML:
1. Simplest feature is making the page dynamic.
2. Can be used to create animations, games, applications, provide new ways of navigating through web sites.
3. DHTML use low-bandwidth effect which enhance web page functionality.
4. Dynamic building of web pages is simple as no plug-in is required.
5. Facilitates the usage of events, methods and properties and code reuse
Features of DHTML:
1. Simplest feature is making the page dynamic.
2. Can be used to create animations, games, applications, provide new ways of navigating through web sites.
3. DHTML use low-bandwidth effect which enhance web page functionality.
4. Dynamic building of web pages is simple as no plug-in is required.
5. Facilitates the usage of events, methods and properties and code reuse
Q) Write a
brief note on JavaScript?
JavaScript
was developed by Netscape (company name) & initially called Livescript.
Later Microsoft developed and adds some futures Live script then it is called
“Jscript”. Jscript is nothing but Java script. We cannot create own classes in
java script.
Java script is designed to add
interactivity to HTML pages. It is usually embedded directly into html pages.
Java script is mainly useful to improve
designs of WebPages, validate from data at client side, detects (find)
visitor’s browsers, create and use to cookies, and much more.
Java script
is also called light weight programming language, because Java `script is
return with very simple syntax. Java script is containing executable code.
Java script is also called interpreted
language, because script code can be executed without preliminary compilation.
Creating
a java script:
- html script tag is used to
script code inside the html page.
<script> </script>
The script is containing 2
attributes. They are
1)
Language attribute: -
It represents name of scripting language such as JavaScript, VbScript.
<script
language=“JavaScript”>
2)
Type attribute: - It
indicates MIME (multi purpose internet mail extension) type of scripting code.
It sets to an alpha-numeric MIME type of code.
<script type=“text /
JavaScript”>
Location
of script or placing the script: -
Script code can be placed in both head & body section of html page.
Script
in head section Script in body
section
<html> <html>
<head> <head>
<script
type=“text / JavaScript”> <script
type= “text / JavaScript”>
Script code here </script>
</script> </head>
</head> <body>
<body> Script code here
</body> </body>
</html> </html>
Scripting
in both head & body section: -
we can create unlimited number of scripts inside the same page. So we can
locate multiple scripts in both head & body section of page.
Ex: -
<html>
<head>
<script type=“text /
JavaScript”>
Script code here
</script>
</head>
<body>
<script
type=“text / JavaScript”>
Script code here
</script>
</body>
</html>
Program: -
<html>
<head>
<script
language="JavaScript">
document.write("hai
my name is Mahaboob Shaik")
</script>
</head>
<body
text="red">
<marquee>
<script
language="JavaScript">
document.write("hai
my name is Sunil Kumar Reddy")
</script>
</marquee>
</body>
</html>
Q) What is a
variable? How to declare a variable in javascript.
Declaring
variable: - variable is a memory location where data can be stored. In java
script variables with any type of data are declared by using the keyword ‘var’.
All keywords are small letters only.
var a; a=20;
var str; str=
“Sunil”;
var c; c=’a’;
var d; d=30.7;
Explain
different types of operators in Javascript.
Operators: - when ever you combined
operators & operands then it is called operation. There are 3 types of
operators.
Unary
operator: - if
operator acts upon single operand then it I called unary operator.
Binary
operator: -if
operator acts upon two operands then it I called binary operator.
Ternary operator: - if operator acts upon
three operands then it I called ternary operator
1) Arithmetic
operators: - + , - , * , / , % , ++ , --
a=20;
- a; // - operator act upon only single operand,
so it is called unary operator.
a=20;
b=40;
a - b; // - operator act upon only single operand, so it is called
binary operator.
*, / , % à pure binary operators.
2) Assignment
operators: -
= is 1st category à
it assigns variables.
+ = , - = , * = , / = , % = à 2nd category.
These sets of operators are
compound assignment operators & combine couple of the statements.
a = a + b; a+=b; // both are same.
3) Relational
operators: - < , > , > = ,
< = , = =
! = = , = = = , ! = = = (newly
defined)
When you compare two quantities, we can use
relational operators.
*Ex: -
a=20;
b=“20”;
a==bà returns true
a===b à returns false.
Because = = checks only content
of variable, = = = checks both data & type of data of variable in java
script.
4) Logical
operators: - && , || , !
Compare two or more quantities
we can use logical operators. These operators are just like boolean (true /
false)
((cond1)&&(cond2)&&(cond3))
All conditions must be true it
is true otherwise false.
((cond1)||(cond2)||(cond3))
Any one condition is true it is
true otherwise false.
5) Conditional
operators: - : , ?
var1=(cond)?var2:var3
Ex: - a=20; b=30;
big=(a>b)?a:b
document.write(big)
6) New operator:
- new operator is creating one object dynamically.
var obj=new classname( )
Ex: - var d=new Date( );
d.getMonth( );
Q) Give a
brief note on Conditional statements in Javascript.
Conditional
statements: -
In Java Script conditional statements are
useful to excuse different action for different decisions (conditions).
if
statement.
if-else
statement.
switch
statement.
if statement
is useful to perform(execute) a single statement or group of statements when
the condition is true.
if – else
statement is useful to execute a one block of code from two blocks where one
condition.
Switch
statement is very frequently to select one of many blocks of code for
execution.
Ex: -
<HTML>
<BODY>
<script
language="JavaScript">
var d=new
Date( );
var day=d.getDay(
);
switch(day)
{
case 0:
document.write("enjoy
Sunday");
break;
case 1:
document.write("learning
Monday");
break;
case 2:
document.write("popper
Tuesday");
break;
case 3:
document.write("middle
Wednesday");
break;
case 4:
document.write("temple
Thursday");
break;
case 5:
document.write("finally
Friday");
break;
case 5:
document.write("super
Saturday");
break;
default :
document.write("I
am looking forward for this week end");
}
</script>
</BODY>
</HTML>
O/P: - learning Monday
Q) Explain
different types of loops in Javascript.
Control
structures :-( loops)
In java
script loops are useful to perform one block of code repeatedly for specified
no of times. There are 3 types of loops.
while loop
do-while
loop
for loop.
1) while
loop:- while loop is useful to execute a block of code repeatedly bussed on
condition. It is also entry controlled loop.
Syntax: - while(cond) { --- }
Ex: - <HTML>
<HEAD>
<TITLE>
Natural No's up to 100 using while </TITLE>
</HEAD>
<BODY>
<script
language="JavaScript">
a=1;
while(a<=100)
{
document.write(a+" ");
a++;
}
</script>
</BODY>
</HTML>
O/P: - 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100
2) do-while
loop: - do-while loop is useful to execute a block of code repeatedly based
on condition. It is also called exit controlled loop.
Syntax: - do { --- } while(cond);
Ex: - <HTML>
<HEAD>
<TITLE>
Fibonacci series up to 10 </TITLE>
</HEAD>
<BODY>
<script
language="JavaScript">
a=0;
b=1;
document.write(
a+" "+b+" ")
c=2;
do
{
s=a+b;
document.write(
s+" ");
c++;
a=b;
b=s;
}
while
(c<10);
</script>
</BODY>
</HTML>
O/P: - 0 1 1 2 3 5 8 13 21 34
3) for
loop: -
Syntax: - for(initialization; cond;
(inc / dec)) { ------ }
Ex: - <HTML>
<HEAD>
<TITLE>
Prime no's up to 100 </TITLE>
</HEAD>
<BODY>
<script
language="JavaScript">
for(i=0;i<=100;i++)
{
c=0;
for(j=0;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
document.write(
i+" ");
}
</script>
</BODY>
</HTML>
O/P: - 2 3 5 7 11 13 17 19 23 29 31
37 41 43 47 53 59 61 67 71 73 79 83 89 97
No comments:
Post a Comment