CSS UNIT-I Notes
CSS UNIT-I Notes
CSS UNIT-I Notes
KADAM
<html>
<head>
<title>Logical Operation</title>
<script language="javascript" type="text/javascript">
var a=10;
var name="sampada";
var b=true;
document.write("Entered number : "+a);
document.write("<br>");
document.write("Entered name : "+name);
document.write("<br>");
document.write("Entered boolean value : "+b);
</script>
</head>
<body>
</body>
</html>
10
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Output:
1. Arithmetic operators
2. Comparison operators
3. Logical operators
4. Assignment operators
5. Bitwise operators
1. Arithmetic operators:
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
11
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var a=20
var b=10;
document.write("Addition is : "+(a+b));
document.write("<br>");
document.write("Substration is : "+(a-b));
document.write("<br>");
document.write("Multiplication is : "+(a*b));
document.write("<br>");
document.write("Division is : "+(a/b));
</script>
</body>
</html>
Output:
<html>
<head>
<title>Average of three number</title>
<script language="javascript" type="text/javascript">
var a=10;
var b=20;
var c=30;
var avg=(a+b+c)/3;
document.write("Average of three numbers= "+avg);
</script></head><body></body></html>
12
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Output:
2. Comparison operators
Operator Description
<html>
<head>
<title>Comparison Operation</title>
<script language="javascript" type="text/javascript">
var a=10,b=5,c="10";
document.write("value of a : "+a);
document.write("<br>");
document.write("value of b : "+b);
document.write("<br>");
document.write("value of c : "+c);
document.write("<br>");
13
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Output:
3.Logical Operators:
Operator Description
logical AND. It check whether two operands are non-zero. If yes then returns
&&
1 otherwise 0.
|| logical OR. It check whether any one of the two operands is non-zero.
14
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
<title>Logical Operation</title>
<script language="javascript" type="text/javascript">
var a=10,b=5,
document.write("value of a : "+a);
document.write("<br>");
document.write("value of b : "+b);
document.write("<br>");
document.write("value of c : "+c);
document.write("<br>");
document.write((a>b)&&(a!=b)); // (10>5) && (10!=5) i.e.true
document.write("<br>");
document.write((a<b)||(a!=b)); // (10<5) && (10!=5) i.e.true
document.write("<br>");
document.write(!(a<b)); // (!(10<5)) i.e true
</script>
</head>
<body>
</body></html>
Output:
4.Assignment Operators:
Assignment operators assign values to JavaScript variables.
15
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
<script language="javascript" type="text/javascript">
var a=10;
var b=20;
a=b;
document.write("a=b is "+a);
a+=1;
document.write("<br>a+=b is "+a);
a-=1;
document.write("<br>a-=b is "+a);
a*=5;
document.write("<br>a*=b is "+a);
a/=2;
document.write("<br>a/=b is "+a);
a%=2;
document.write("<br>a%=b is "+a);
</script>
</head>
<body>
</body>
</html>
Output:
16
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
5.Ternary Operator:
Syntax:
<condition> ? <value1>:<value2>
<html>
<head>
<script language="javascript" type="text/javascript">
var a=10;
var b=20;
var c=(a>b)?a:b;
document.write(c);
</script>
</head>
<body>
</body>
</html>
Output:
17
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
1.5.1 if Statement
Syntax:
if (condition) {
// block of code to be executed if the condition is true
}
Output:
18
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Syntax:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
<html>
<head>
<title>Average of three number</title>
<script language="javascript" type="text/javascript">
var a=10;
var b=20;
if(a>b)
{
document.write("a is greater than than b");
}
else
{
document.write("b is greater than than a");
}
</script></head><body></body></html>
Output:
19
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Syntax:
if (condition1)
{
// block of code to be executed if condition1 is true
} else if (condition2)
{
// block of code to be executed if the condition1 is false and condition2 is true
} else
{
// block of code to be executed if the condition1 is false and condition2 is false
}
<html>
<head>
<script language="javascript" type="text/javascript">
var subject1=74;
var subject2=56;
var subject3=80;
var subject4=79;
var subject5=89;
var avg=(subject1+subject2+subject3+subject4+subject5)/5;
document.write("Your Percentage is = "+avg);
document.write("<br>");
if(avg>75)
{
document.write("Your grade is = Distinction");
}
else if((avg>=60)&&(avg<75))
{
document.write("Your grade is = First Class");
}
else if((avg>=40)&&(avg<60))
{
document.write("Your grade is = Second Class");
}
20
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
else if((avg>=35)&&(avg<40))
{
document.write("Your grade is = Pass");
}
else
{
document.write("Your grade is :Fail");
}
</script>
</head>
<body>
</body>
</html>
Output:
The switch statement is used to perform different actions based on different conditions.
Use the switch statement to select one of many code blocks to be executed.
Syntax:
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
21
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
<script language="javascript" type="text/javascript">
var a=prompt("Enter number from 1 to 4");
switch(a)
{
case "1":
document.write("perform Addition");
break;
case "2":
document.write("Perform substraction");
break;
case "3":
document.write("Perform Multiplication");
break;
case "4":
document.write("Perform Division");
break;
default:
document.write("Number sholud be in between 1 to 4");
}
</script>
</head>
<body></body></html>
Output:
22
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Syntax:
<html>
<head>
<script language="javascript" type="text/javascript">
var a;
for(a=0;a<10;a++)
{
document.write("Welcome student<br>");
}
</script>
</head>
<body>
</body>
</html>
23
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Output:
Output:
24
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
let keyword is used to declare variables in Javscript. The var keyword can also be
used to declare variables, but the key difference between them lies in their scopes.
var is function scoped while let is block scoped.
Program:Write a javascript to demonstrate for… In loop.
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var person={
name:"sampada",
age:30,
classname:"TYCM"
};
for(let x in person)
{
document.write(person[x]);
document.write("<br>");
}
</script>
</body>
</html>
Output:
25
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
txt=txt+person[x]+" ";
}
document.write(txt);
</script>
</head>
<body>
</body>
</html>
Output:
26
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
The while loop loops through a block of code as long as a specified condition
is true.
Syntax:
while (condition) {
// code block to be executed
}
<html>
<head>
<script language="javascript" type="text/javascript">
var i=1;
while(i<=10)
{
document.write(i+"<br>");
i++;
}
</script>
</head>
<body>
</body>
</html>
Output:
27
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
The do...while is used when you want to run a code block at least one time.
Syntax:
do {
code block to be executed
}
while (condition);
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var a=1;
do
{
document.write(a+"<br>");
a=a+1;
}while(a<=10)
</script>
</body>
</html>
Output:
28
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
1.8
1.8.1 Querying and Setting properties:
The dot (.) operator or square bracket ( [] ) are used to obtained values of properties.
To get properties from student object:
var name=student.name;
var rollno=student.rollno;
if using square brackets, the value within the brackets must be an expression that evaluates
to a string that contains the desired property name.
29
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
Output:
<html>
<head>
<script language="javascript" type="text/javascript">
var person={
firstname:"sampada",
lastname:"kadam",
age:30,
eyecolor:"black"
};
delete person.eyecolor;
document.write("Your First Name is :"+person.firstname);
document.write("<br>Your Second Name is :"+person.lastname);
document.write("<br>Your Age is :"+person.age);
document.write("<br>Your eyecolor is :"+person.eyecolor);
</script>
</head>
<body></body></html>
Output:
30
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var student={
name:"sampada",
rollno:30,
get getname(){
return this.name;
}
};
document.write("Student Name is : "+student.getname);
</script>
</body>
</html>
Output:
31
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
When a value is set, the setter is called and passed the value that was set.
Set – a function with one argument that is called when the property is set.
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var student={
name:"sampada",
rollno:30,
set setname(value)
{
this.name=value;
}
};
student.setname="shourya";
document.write("Student Name is : "+student.name);
</script>
</body>
</html>
Output:
32
CLIENT SIDE SCRIPETING (CSS) -22519 ( UNIT-I ) MRS. S.S.KADAM
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
var student={
name:"sampada",
rollno:30,
get getname(){
return this.name;
},
set setname(value){
this.name=value;
}
};
document.write("Student Name is : "+student.getname);
student.setname="shourya";
document.write("<br>Student Name is : "+student.getname);
</script>
</body>
</html>
Output:
33