0% found this document useful (0 votes)
1 views

hemant css practicals 1 to 4 (1)

..
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

hemant css practicals 1 to 4 (1)

..
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Name: Hemant Sureshrao Maraskolhe

Subject: CSS
Enrollment :23310250269
PRACTICAL NO 1
AIM : Develop Javascript to use decision making and looping statements.

Basic concept:
Decision Making Statements
• Decision Making in programming is similar to decision making in real life.
• A programming language uses control statements to control the flow of execution of
the program based on certain conditions.

• JavaScript’s conditional statements are:


1) if

2) if-else

3) if…else…if

4) switch
1) if statement

• if statement is the most simple decision making statement.

• It is used to decide whether a certain statement or block of statements will be


executed or not.

• If a certain condition is true then a block of statement is executed otherwise not.

• Syntax:
if(condition)
{
statements;
}
2) if…else statement

• The if-else statement has two parts if block and else block.

• If the condition is true then if block (true block) will get executed and if the condition
is false then else block (false block) will get executed.
• Syntax:
if(condition)
{
statement 1: //true block

}
e
l
s
e
{
statement 2; //false block
}
3) if…else ladder

• The if…else ladder is use to test set of condition in a sequence.


• Number of condition are given in a sequence with subsequent statement.

• If any one of the given condition is satisfied then the related statement are executed,
if all the condition does not satisfied then default statement will be executed.

• Syntax:
if(condition 1)
{
statement 1;
}
else if(condition 2)
{
statement 2;
}
else if(condition
n)
{
statement n;
}
else
{
statement m;
}
4) switch statement

• The objective of a switch statement is to give an expression to evaluate and several


different statements to execute based on the value of the expression.

• The interpreter checks each case against the value of the expression until a match is
found. If nothing matches, a default condition will be used.

• Syntax:
switch(expression)
{
case
constant_expression1;state
ment;
break;
case constant_expression2;
statement; break;
case constant_expressionN;
statement; break;

default; statement
m;
}
Looping Statements

• Looping in programming languages facilitates the execution of a set of


instructions/functions repeatedly while some condition evaluates to true.

• For example, suppose we want to print “Hello World” 10 times this is possible with
the help of loops.

• There are mainly two types of loops:

1) Entry Controlled loops: In this type of loops the test condition is tested
before entering the loop body. For Loop and While Loop are entry controlled loops.
2) Exit Controlled Loops: In this type of loops the test condition is tested or
evaluated at the end of loop body. Therefore, the loop body will execute atleast once,
irrespective of whether the test condition is true or false. do-while loop is exit
controlled loop.
Following are the types of loops in JavaScript:
1) while loop

2) do-while loop

3) for loop

Program:
<html>
<title>Decision Making and Looping Statement</title>
<head>
<script language= "javascript" type="text/javascript">
var ch=parseInt(prompt("1.Even-Odd 2.Factorial"));
var a =parseInt(prompt("Enter a Number"));
switch(ch)
{
case 1:
if(a%2==0)
{
alert(a+" is even Number");
}
else
{
alert(a+" is Odd Number");
}
break;

case 2:
var fact=1;
for(var i=1;i<=a;i++)
{
fact=fact*i;
}
alert(fact+" is Factorial");
break;

default:
alert("Error 405");

}
</script>
</head>
</html>
OUTPUT :-
.

Marks Obtained Dated signature of


Teacher
Process Related(15) Product Related(10) Total(25)
PRACTICAL NO 2

AIM : Develop javascript to implement Array functionalities.

Basic concept :
JavaScript Arrays : An array is a special variable, which can hold more than one value
at a time. JavaScript arrays are used to store multiple values in a single variable.
Declaring an array There are 2 ways to construct an array in JavaScript 1) By array
literal

2) By using an Array constructor (using new keyword)


1) By array literal
This is the easiest way to create a JavaScript
Array. Syntax:
var array_name = [item1, item2, …]; Example:
var fruits = ["Apple", "Orange", "Plum"];
2) By using an Array constructor (using new keyword)
You can also create an array using Array constructor with new keyword This
declaration has five parts:

1) var keyword

2) Array name

3) Assignment operator

4) new operator
Program Code:-
<html>
<title>Array Functionalities</title>
<head>
<script language= “javascript” type=”text/javascript”>

Var a=new Array(50,45,80,95,43,22);


Var ch=parseInt(prompt(“Array Methods for Implementation (array is[50,45,80,95,43,22])\n
1.reverse\n 2.pop\n 3.sort\n 4.shift”));

Switch(ch){
Case 1:
Var rev=a.reverse();
Alert(“Reverse array is “+rev);
Break;

Case 2:
a.pop();
alert(“(last element is deleted)\n Array is “+a);
break;

case 3:
var so=a.sort();
alert(“Sorted Array is “+so);
break;

case 4:
a.shift();
alert(“(First Element is Deleted)\n Array is “+a);
break;

default:
alert(“Error 405”);
}

</script>
</head>
</html>

Output:-
Marks Obtained Dated signature of
Teacher
Process Related(15) Product Related(10) Total(25)
PRACTICAL NO 3

Aim : Develop Javascript to implement functions.

Basic Concept:
Functions in Javascript :- function is a group of reusable code which can be called
anywhere in the program. This eliminates the need to rewrite the same code.
Functions allow a programmer to divide a big program into a smaller and
manageable function. JavaScript provides functions just like other programming
languages. A JavaScript function can be defined using the function keyword.
There are mainly two advantages of JavaScript functions.
1. Code reusability: We can call a func on several mes whenever we need it.
2. Less coding: It reduces the line of code and makes our program compact.

Program:-
<html>
<head>
<title>Fuction Demo</title>
<script>

Function add(a,b)
{
Return a+b;
}
Function sub(a,b)
{
Return a-b;
}
Function mul(a,b)
{
Return a*b;
}
Function div(a,b)
{
Return a/b;
}
Var a=parseInt(prompt(“Enter First Number”));
Var b=parseInt(prompt(“Enter Second Number”));
Var n1=add(a,b);
Var n2=sub(a,b);
Var n3=mul(a,b);
Var n4=div(a,b);
Document.write(“<br>Addition is:- “+n1);
Document.write(“<br>Subtraction is:- “+n2);
Document.write(“<br>Multiplication is:- “+n3);
Document.write(“<br>Division is:- “+n4);
</script>
</head>
</html>

Output:

Marks Obtained Dated signature of


Teacher
Process Related(15) Product Related(10) Total(25)
PRACTICAL NO 4
AIM: Create a webpage to implement Form Event. [Part 1]

Basic concept: HTML Form Events


When JavaScript is used in HTML pages, JavaScript can "react" on these events. An HTML
event can be something the browser does, or something a user does. The simple example of
an event is a user clicking the mouse or pressing a key on the keyboard.
Some examples of HTML events:
• An HTML web page has finished loading
• An HTML input field was changed
• An HTML button was clicked

Program:-
<!DOCTYPE html>
<html>
<head>
< tle> Form Event </ tle>
<script>
func on changeColor(color)
{
var panel = document.getElementById('panel');
document.body.style.backgroundColor = color;
panel.innerHTML = "Background color is set to: " + color.toUpperCase();
}
</script>
</head>
<body onload="changeColor('red')">
<p>Select an op on to change the background color of the page</p>
<form name="myform">
<input type="radio" name="color" value="red" onchange="changeColor(this.value)" checked="false">RED<br />
<input type="radio" name="color" value="GREEN" onchange="changeColor(this.value)">GREEN<br />
<input type="radio" name="color" value="blue" onchange="changeColor(this.value)">BLUE<br />
</form>
<p id="panel"></p>
</body>
</html>
</html>
Output:-

Marks Obtained Dated signature of


Teacher
Process Related(15) Product Related(10) Total(25)

You might also like