Javascript
Javascript
F/ TL / 018
Rev.00 Date 20.03.2020
B.Tech-IT Scripting Languages Lab -Lab Manual BIT18L06
LAB MANUAL
LABORATORY MANUAL
AIM:
ALGORITHM:
PROGRAM:
<html>
<head>
<script>
function add()
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a + b;
document.getElementById("answer").value= c;
function sub()
1
FORM NO. F/ TL / 018
Rev.00 Date 20.03.2020
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a - b;
document.getElementById("answer").value= c;
function mul()
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a * b;
document.getElementById("answer").value= c;
function div()
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a /b;
document.getElementById("answer").value= c;
function mod()
{
2
FORM NO. F/ TL / 018
Rev.00 Date 20.03.2020
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a *b;
document.getElementById("answer").value= c;
</script>
</head>
<body>
<button onclick="add()">Add</button>
<button onclick="sub()">Sub</button>
<button onclick="mul()">Mul</button><br>
</body>
</html>
OUTPUT:
3
FORM NO. F/ TL / 018
Rev.00 Date 20.03.2020
4
5
Ex.No:2
Java script program to search an element in an array
AIM:
ALGORITHM:
OpenNotepad
Typethejavascriptprogramtosearchanelementinanarrayofsize“N”.
Savethefilewith.htmlasextension.
Openthehtml fileinbrowser.
Displaytheoutput.
Stop.
PROGRAM:
<html>
<head>
else
for(i=0;i<n;i++)
{
6
var num=prompt("Please enter element of array"," ");
document.frm.arrayTxt.value=document.frm.arrayTxt.value+num+"\n"; a[i]=parseInt(num);
var flag=0;
if(a[i]==search)
flag=1; p=i+1;
if(flag==1)
</script>
</head>
<body bgcolor="lightgreen">
<form name="frm">
<br>
<br>
</textarea>
<br>
</form>
</body>
</html>
OUTPUT:
8
9
Ex.No:3
Java script program to find GCD of two numbers
AIM:
ALGORITHM:
OpenNotepad
TypethejavascriptprogramtofindGCDoftwo numbers.
Savethefilewith.htmlasextension.
Openthehtml fileinbrowser.
Displaytheoutput.
Stop.
PROGRAM:
<html>
<body bgcolor="yellow">
<center>
<h1>GCD calculator</h1>
</div>
var n1=document.getElementById("b1").value;
10
var n2=document.getElementById("b2").value; var result=document.getElementById("result");
n1=Number(n1);
let count=1;
gcd = count;
count++;
</script>
</center>
</body>
</html>
11
OUTPUT:
12
Ex.No:4
Java script program to perform string manipulation
function
AIM:
ALGORITHM:
OpenNotepad
Typethejavascriptprogramforstringmanipulation.
Savethefilewith.htmlasextension.
Openthehtml fileinbrowser.
Displaytheoutput.
Stop.
PROGRAM:
STRING LENGTH
<html >
<head>
String Length
</head>
<body>
<p id ="demo"></p>
<script>
13
let text = "ABCDEFGHIJK"; document.getElementById("demo").innerHTML=text.length;
</script>
</body>
</html>
STRING SUBSTRING
<html>
<head>
String Substring
</head>
<body>
<p id="demo"></p>
<script>
// console.log(substring);
</script>
</body>
</html>
14
STRING SLICE
<html>
<head>
String Slice
</head>
<body>
<p id="demo"></p>
<script>
</script>
</body>
</html>
STRING REPLACEMENT
<html >
<head>
</head>
<body>
15
<button onclick="myFunction()">Try it</button>
<script>
function myFunction(){
let text=document.getElementById("demo").innerHTML;
document.getElementById("demo").innerHTML=text.replace("Micro soft","MGR");
</script>
</body>
</html>
OUTPUT:
16
17
Ex.No:5
A Perl program to display a digital clock which displays
the current time of the server
AIM:
To write a perl program to display a digital clock which displays the currenttimeoftheserver.
ALGORITHM:
Start.
OpenNotepad.
Type the Perl Program to Display a Digital Clock Which Displays theCurrentTimeoftheServer.
UseCGIstasndard
Declarethetime varialbles$sec,$min,$hour,$ampm
Callthelocaltime()in-builtfunction.
Generate the html code output by perl
SaveitasExtensionof.PLFILE.
Copy the generated html code by perl and paste it on notepad and savetheextensionwith.html
Browsethehtmlfileinwebbrowser
PROGRAM:
use strict;
if($hour>12)
$hour=$hour-12;
18
$ampm="PM";
else
$ampm="AM";
OUTPUT:
19
Ex.No:6 Perl Program to Accept the User Name and Display a Greeting
Message Randomly Chosen From a List of 4 Greeting Messages.
Date:
AIM:
To write a Perl Program to Accept the User Name and Display
aGreetingMessageRandomlyChosenFromaListof4GreetingMessages.
ALGORITHM:
Start.
OpenNotepad.
Type a PERL Program to Accept the User Name to Display the GreetingMessageRandomly.
SaveitasExtensionof.PLFILE.
OpenitonChrome.
Stop.
PROGRAM:
$n = int(rand($len)); if (param)
print header( );
print start_html(-bgcolor=>"pink");
print end_html();
else
print header();
print end_html();
21
OUTPUT:
22
Ex.No:7
A Perl Program to Keep Track of the Number of Visitors
Visiting the Web Page and to Display this Count of Visitors,
With Proper Headings.
AIM:
To Write a Perl Program to Keep Track of the Number of Visitors Visiting theWeb Page and to
Display this Count of Visitors,With Proper Headings.
ALGORITHM:
Start.
Open Notepad.
Type a HTML Program to Create a Form.
In the form action call the cgi file for the webpage.
Save it as Extension of.html.
Create a visitor text file by saving.txt
Open a file visitor.txt
Declare a variable $count for counting the no of visitors.
Display the Count by print.
Save it as Extension of .cgi
Open it on the web browser.
Click on Ok button it will display the number of times visit.
PROGRAM:
$count=<FILE>;
$count++;
23
print "<center><h1>You are the visitor number $count";
HTML code
<html>
<body bgcolor="pink">
<center>
<hr>
<form action="/cgi-bin/Lab6b.cgi">
</form>
</body>
</html>
OUTPUT:
24
Ex.No:8
A Perl Program to Display Various Server Information
Like Server Name, Server Software, ServerProtocol ,and
CGI Revision etc
AIM:
To Write a Perl Program to Display Various Server Information Like Server Name, Server Software,
Server Protocol ,and CGI Revision etc.
ALGORITHM:
Start.
Open Notepad.
Type a Program Which Display Various Server Information Like ServerName, Server Software,Server
Protocol ,and CGI Revision.
Save it as Extension of.PL FILE
Open it on Chrome
Stop.
PROGRAM:
25
hr(),
OUTPUT:
26
Ex.No:9
A Perl program to accept the UNIX command from an
HTML form and to display the output of the command
executed.
AIM:
To write a Perl program to accept the UNIX command from an HTML form and to display the output of the command
executed.
ALGORITHM:
Open“Notepad”.
Apply the required HTML coding and save it in the”.html”extension.
Apply the required Perl coding and save it in the ”.pl”extension.
Open the saved file from the“Documents”folder on your computer.
The webpage will appear on the browser.
Use the webpage for its designated purpose.
PROGRAM:
EX9B.html
<html>
<form action="http://localhost/cgi-
bin/5b.pl">Command:<inputtype=textname=com>
<inputtype=submitvalue=submit/>
</form>
</html>
EX9B.pl
#!/usr/bin/perl
useCGI':standard';
#the following line is used for displaying the output of the script in the browser print"Content-
27
type:text/html\n\n";
#take the input command from the browser and store in the variable
$c=param('com');#process the
commandsystem($c);
exit(0);
OUTPUT:
28
Ex.No:10
Python Program to Define a Module to Find Fibonacci
Numbers and Import the Module to Another Program
Using Functions
AIM:
To Write a Python Program to Define a Module to Find Fibonacci Numbers and Import the Module to
Another Program Using Functions.
ALGORITHM:
Start.
OpenPythonCompiler.
TypetheFibonacciProgram.
ImporttheModuletoAnotherProgram.
Runthe Code.
EnteraNumberinFibonacciNumber.
Stop.
PROGRAM:
Fibonacci.py
#Fibonacci numbersmodule
def fib(n): # write Fibonacci series up to n a, b = 0, 1whileb <n:
print(b,end="")a,b=b,a+b
week14.py
#importfibonacci module
importfibonacci
num=int(input("Enter any number to print Fibonacci series "))
fibonacci.fib(num)
29
OUTPUT:
30
Ex.No:11
Python program to find factorial of a number using
recursion function
AIM:
To write a python program to find factorial of a number using recursionfunction.
ALGORITHM:
Start.
OpenPythonCompiler.
Type the Python Program to Find Factorial of a Number UsingRecursionFunction.
Runthe Code.
EntertheFactorialNumber.
Stop.
PROGRAM:
defrecur_factorial(n):
ifn==1:
returnn:
else:
return n*recur_factorial(n-1)num=7
#checkif thenumber isnegativeifnum <0:
print("Sorry, factorial does not exist for negative numbers")elif num==0:
print("Thefactorialof0 is1")else:
print("The factorial of",num, "is", recur_factorial(num));
31
OUTPUT:
32
Ex.No:12
Python Programto Find Largest of Three Numbers
UsingFunctions
AIM:
To Write a Python Program to Find Largest of Three Numbers UsingFunctions
ALGORITHM:
Start.
Open Python Compiler.
Type the Python Program to Find Largest of Three Numbers Using Functions.
Get the 3 inputs of numbers
Define the function largest
Check the condition of greatest among three numbers
Call the largest() function
Run the Code.
Enter the Numbers as input
Stop.
PROGRAM:
num1=int(input("Enterthefirstnumber:"));
num2=int(input("Enter the second number: "));
num3=int(input("Enter theThirdnumber:"));
def
find_Largest():
#functiondefinitionif(num1>=num2) and
(num1>=num2):largest=num1;
elif(num2>=num1) and
(num2>=num3):largest=num2
33
else:
largest=num3
print("Largest number
is",largest)find_Largest(); #functioncall
OUTPUT:
34
Ex.No:13
Python Program That Displays the System Information Such
as
A. ProcessorInformation and
B. MemoryInformationFrom/ ProcFiles
AIM:
To Write a Python Program That Displays the System Information Such as
ALGORITHM:
Start.
Open Python Compiler.
Print the CPU info.
Print the memory info.
Run the Code.
Display the Output.
Stop.
PROGRAM:
# processorprint("Processors:")
with open("/proc/cpuinfo", "r") as
f:info=f.readlines();
cpuinfo=[x.strip().split(":")[1]forxininfoif"mo
delname"inx]
for index, item in
enumerate(cpuinfo):print(""+str(index)+": "+item)
# Memory print("Memory Info: ")with
35
open("/proc/meminfo", "r") as
f:lines=f.readlines()
print(""+lines[0].strip())
print(""+lines[1].strip())
OUTPUT
36
Ex.No:14
Python Program which Demonstrate Divide by Zero Error
and Syntax Error Exception Handling.
AIM:
To Write a Python Program Which Demonstrate Divide by Zero Error
andSyntaxErrorExceptionHandling.
ALGORITHM:
Start.
OpenPythonCompiler.
Type the Python Program Which Demonstrate Divide by Zero Error
andSyntaxErrorExceptionHandling.
Runthe Code.
DisplaytheOutput.
Stop.
PROGRAM:
37
CONTENT BEYOND SYLLABUS
AIM:
ALGORITHM:
PROGRAM:
<html>
<body style=”text=align:center;”>
<h2>GET USER’S SCREEN INFORMATION WITH <br> JAVASCRIPT WINDOWS SCREEN </h2>
<h3>Total Screen size in pixels</h3>
<p>Screen Width= <span id=”width”></span></p>
<p>Screen Height=<span id=”height”></span</p>
<h3>
The screen size in pixels without the stuff blocking part of your viewport
<br>(windows taskbar or history/bookmarks side panel)</h3>
<p>Available screen Width= <span id=”availWidth”></span></p>
<p>Available screen Height= <span id=”availHeight”></span></p>
<h3>Color Depth: number of bits used to display one color</h3>
<p>Screen color Depth = <span id=”colorDepth”></span></p>
<p>Screen Pixel Depth= <span id=”pixelDepth”></span></p>
<script>
document.getElementById(“width”).innerHTML = screen.width;
38
document.getElementById(“height”).innerHTML = screen.height;
document.getElementById(“availWidth”).innerHTML = screen.availWidth;
document.getElementById(“availHeight”).innerHTML = screen.availHeight;
document.getElementById(“colorDepth”).innerHTML = screen.colorDepth;
document.getElementById(“pixelDepth”).innerHTML = screen.pixelDepth;
</script>
</body>
</html>
OUTPUT:
39
Java script program to create an animation
AIM:
ALGORITHM:
Open
Notepad
Type the java script program to create an animation.
Save the file with.html as extension.
Open the html file in browser.
Display the output.
Stop.
PROGRAM:
<html>
<style> #container
40
</style>
<body>
<div id ="container">
<div id ="animate"></div>
</div>
<script>
clearInterval(id);
} else { pos++;
</script>
</body></html>
41
OUTPUT:
42
43