CSS Practical 01-05
CSS Practical 01-05
Thoery:
JavaScript is a scripting or programming language that allows you to implement
complex features on web pages. It is well-known for the development of web
pages, and many non-browser environments also use it.
<html>
<head>
<body>
<script>
// Executable code
</script>
</body>
</head>
</html>
Program Code :
<html>
<head>
<title> Arithematic Operation</title>
<script type=”text/javascript”>
var a,b;
{
a=(parseInt(prompt("Enter a number")));
b=(parseInt(prompt("Enter second number")));
}
document.write("Addition is :- "+(a+b));
document.write("<br> Substraction is :- "+(a-b));
document.write("<br> Multiplication is :- "+(a*b));
document.write("<br> Division is :- "+(a/b));
document.write("<br> Modulus Division is :- "+(a%b));
document.write("<br> Increement of First number is :- "+(++a));
document.write("<br> Increement of Second number is :- "+(++b));
document.write("<br> Decreement of First number is :- "+(--a));
document.write("<br> Decreement of Secondd number is :- "+(--b));
</script>
</head>
</html>
Output :
Thoery:
Decision Making Statements :
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
statement:
Syntax:
if (condition) {
//true block
}
2) if-else
statement:
Syntax:
if(condition){
//true block
} else {
//false block
}
3) if…else…if
Syntax:
if(condition
{
if(condition1from1){
//true block
} else {
//false block
}else{
//false block from condition 2
}}
Looping Statements :
Looping in programming languages facilitates the execution of a set of
instructions/functions repeatedly while some condition evaluates to true.
Following are the types of loops in JavaScript:
1) while loop
2) do-while loop
3) for loop
<html>
<head>
<script type="text/javascript">
var a=parseInt(prompt("Enter First Number : "));
var b=parseInt(prompt("Enter Second Number : "));
var c=parseInt(prompt("Enter Third Number : "));
if(a>b && a>c)
{
document.write(a+" Number is Greater ");
}
else if(b>a && b>c)
{
document.write(b+" Number is Greater ");
}
else if(c>a && c>b)
{
document.write(c+" Number is Greater ");
}
else
{
document.write("All Number are Equals");
}
</script>
</head>
</html>
Output:
<html>
<head>
<script type="text/javascript">
var a=prompt("Enter a Number : ");
for(var i=1;i<=10;i++)
{
document.write("<br>"+a+" * "+i+" = "+(a*i));
}
</script>
</head>
</html>
Output:
Marks Obtained Dated
Signature
of Teacher
Process Product Total
Related(10) Related(15) (25)
Practical 3
Aim : Develop a Javascript to implement Array functionalities.
Thoery:
What is an Array?
An array is a special variable, which can hold more than one value at a time.
Creating an Array Using an array literal is the easiest way to create a JavaScript
Array.
There are two ways of declaring an array in Javascript
1) By array literal :
This is the easiest way to create a JavaScript Array.
Syntax: var array_name = [item1, item2,
[“Red”,”Yellow”,”Orange”]
<html>
<title>Practical 3</title>
<body>
<script>
var strArray=new Array("Vinit","Soham","Rakesh","Sanjay","Mayur")
var numArray=new Array(10,20,22.5,30,87,88);
document.write("<br> Original String Array elements are : "+strArray);
document.write("<br> Original Numeric Array elements are : "+numArray);
numArray.push(55);
document.write("<br> New Numeric Array elements after push() : "+numArray);
strArray.push("Monish");
document.write("<br> New String Array elements after push() : "+strArray);
</script>
</body>
</html>
Output:
Thoery:
Function
JavaScript functions are used to perform operations. We can call JavaScript
function many times to reuse the code.
2. Less coding: It makes our program compact. We don’t need to write many lines
of code each time to perform a common task.
JavaScript Function Syntax:
function function_Name([arg1, arg2, ...argN])
{
//code to be executed
}
JavaScript Functions can have 0 or more arguments.
Program Code :
<html>
<title>Practical 4</title>
<body>
<script>
var patient_name,patient_no,patient_mob_no,patient_add;
function accept(){
patient_name=prompt("Enter Patient Name: ");
patient_no=parseInt(prompt("Enter Patient Number : "));
patient_mob_no=prompt("Enter Patient Mobile Number: ");
patient_add=prompt("Enter Patient Address : ");
}
function show(){
document.write("<br> Patient Name is "+patient_name);
document.write("<br> Patient Number is "+patient_no);
document.write("<br> Patient Mobile Number is "+ patient_mob_no);
document.write("<br> Patient Address is "+patient_add);
}
accept();
show();
</script>
</body>
</html>
Output :
Thoery:
String:
A JavaScript string stores a series of characters like "Vinit Sahare". A string can be
any text inside double or single quotes:
let carName1 = "Volvo XC60";
let carName2 = 'Volvo XC60';
Advantage of Strings:
There are some advantages of JavaScript Strings:
Regular Expressions: Strings can be easily manipulated and searched using regular
expressions, which provide powerful pattern matching capabilities for validating and
extracting information.
Built-in Methods: JavaScript provides a rich set of built-in methods for string
manipulation, such as charAt(), substring(), split(), replace(),
toUpperCase(), toLowerCase(), and more. These methods simplify common
tasks.
Concatenation: Strings can be easily concatenated using the ‘+’ operator or
template literals (backticks), allowing for dynamic string creation and formatting.
Readability: Strings are easy to read and write, making code more understandable,
especially when used for messages, prompts, and user
interface elements.
<html>
<head><title> String Implementation</title>
<script type="text/javascript">
</script>
</head>
</html>
Output :