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

Javascript

The document is a laboratory manual for the Scripting Languages Lab (BIT18L06) for B.Tech IT students, detailing various experiments and programming tasks using JavaScript, Perl, and Python. It includes objectives, algorithms, and sample programs for tasks such as arithmetic operations, searching elements in arrays, and displaying server information. The manual is structured to guide students through practical applications of scripting languages in a hands-on learning environment.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Javascript

The document is a laboratory manual for the Scripting Languages Lab (BIT18L06) for B.Tech IT students, detailing various experiments and programming tasks using JavaScript, Perl, and Python. It includes objectives, algorithms, and sample programs for tasks such as arithmetic operations, searching elements in arrays, and displaying server information. The manual is structured to guide students through practical applications of scripting languages in a hands-on learning environment.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

FORM NO.

F/ TL / 018
Rev.00 Date 20.03.2020
B.Tech-IT Scripting Languages Lab -Lab Manual BIT18L06

LAB MANUAL

Subject Name: SCRIPTING LANGUAGES LAB


LabSubject code: BIT18L06
Programme Name: B. Tech, IT
Regulation:2018
FORM NO. F/ TL / 018
Rev.00 Date 20.03.2020

LABORATORY MANUAL

Faculty Engineering and Technology


Course , Department
& Specialization ( If B.Tech/Information Technology
applicable)

Year / Sem. / Sec. IV/7 th/A

Sub code BIT18L06

Sub Name SCRIPTING LANGUAGES LAB

LIST OF EXPERIMENTS Linked Page


NO.
PO/PSO NO
Java script program to perform Arithmetic operations PO1,PO2,PO5/
1 1
PSO2
Java script program to search an element in an array PO1,PO2, 6
PO3,PO5/
2 PSO2
Java script program to find GCD of two numbers PO1,PO2, 10
3 PO3,PO5/
PSO2
String manipulation function in Java Script PO1,PO2, 13
4 PO3,PO5/
PSO2
Perl program to display a digital clock which displays the current PO1,PO2, 18
5 time of the server PO3,PO5/
PSO2
Perl program to accept the use and display a greeting message PO1,PO2, 20
6 randomly chosen from a list of 4 greeting messages PO3,PO5/
PSO2
Perl program to keep track of the number of visitors visiting the PO1,PO2, 23
7 webpage and to display this count of visitors with proper heading PO3,PO5/
PSO2
Perl program to display various server information like server PO1,PO2, 25
8 name, software, protocol and CGI revision etc PO3,PO5/
PSO2
UNIX command from HTML forms and to display output of PO1,PO2, 27
9 command executed PO3,PO5/
PSO2
Program to define a module to find Fibonacci number and import PO1,PO2, 29
10 the module to another program using function PO3,PO5/
PSO2
Python program to find factorial of a number using recursion PO1,PO2, 31
11 function PO3,PO5/
PSO2
Python program to find largest of three number using function PO1,PO2, 33
12 PO3,PO5/
PSO2
Python program that displays the system information such as PO1,PO2, 35
PO3,PO5/
13 a) Processing information and PSO2
b) Memory information from/proc files
Python program which demonstrate divide by zero error and PO1,PO2, 37
14 syntax error exception handling PO3,PO5/
PSO2
Java script program to print screen information PO1,PO2, 38
15 PO3,PO5/
PSO2
To create an animation using Java script PO1,PO2, 40
16 PO3,PO5/
PSO2
FORM NO. F/ TL / 018
Rev.00 Date 20.03.2020
Ex.No:1
Java script program to perform all arithmetic operations

AIM:

To write a javas cript program to perform all arithmetic operations.

ALGORITHM:

 Open your notepad.


 Write a html code for performing all arithmetic operation.
 Save the code with .htm as extension
 Open the file with chrome and give two numbers.The answer will be executed.

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>

Enter the First number :<input id="first"><br>

Enter the Second number: <input id="second"><br>

<button onclick="add()">Add</button>

<button onclick="sub()">Sub</button>

<button onclick="mul()">Mul</button><br>

Result of the operation: <input id="answer">

</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:

To write a java script program to search an element in an array.

ALGORITHM:
 OpenNotepad

 Typethejavascriptprogramtosearchanelementinanarrayofsize“N”.

 Savethefilewith.htmlasextension.

 Openthehtml fileinbrowser.

 Displaytheoutput.

 Stop.
PROGRAM:

<html>

<head>

<script type="text/javascript"> function show_prompt()

var n=document.frm.text1.value; if(n=="")

alert("Please enter the array size");

else

var a=new Array(); var temp;

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;

var search=prompt("Enter the element to be searched ",""); for(i=0;i<n;i++)

if(a[i]==search)

flag=1; p=i+1;

if(flag==1)

alert("Element " +search + " found at position " +p); else

alert("Sorry!, Element " + search + " not found "); document.frm.text1.value="";


document.frm.arrayTxt.value="";

</script>

</head>

<body bgcolor="lightgreen">

<form name="frm">

<h3>To find an element in a given array </h3>

<hr color="green"> Enter the array size :

<input type="text" name="text1">

<br>

<br>

<input type="button" onclick="show_prompt()" value="Submit">


7
<br>

<textarea name="arrayTxt" rows="10" cols="4">

</textarea>

<br>

</form>

</body>

</html>

OUTPUT:

8
9
Ex.No:3
Java script program to find GCD of two numbers

AIM:

To write a java script program to find GCD of two numbers.

ALGORITHM:

 OpenNotepad
 TypethejavascriptprogramtofindGCDoftwo numbers.
 Savethefilewith.htmlasextension.
 Openthehtml fileinbrowser.
 Displaytheoutput.
 Stop.

PROGRAM:

<html>

<body bgcolor="yellow">

<center>

<h1>GCD calculator</h1>

<input type="text" id="b1" placeholder="Enter first number">

<input type="text" id="b2" placeholder="Enter second number">

<input type="button" value="Calculate" id="btnCalc">

<div id="result" style="width:250px; border: 5px solid black;position:


absolute;top:100px;left:500;padding:20px">

</div>

<script> function gcd(){

var n1=document.getElementById("b1").value;
10
var n2=document.getElementById("b2").value; var result=document.getElementById("result");
n1=Number(n1);

n2=Number(n2); let gcd = 1;

let count=1;

while(count <= n1 && count <= n2)

// Checks if i is factor of both integers if(n1 % count==0 && n2 % count==0)

gcd = count;

count++;

result.textContent= "G.C.D of "+n1+" and "+n2+" is "+gcd+" \n";

var btnCalc=document.getElementById("btnCalc"); btnCalc.onclick=gcd;

</script>

</center>

</body>

</html>

11
OUTPUT:

12
Ex.No:4
Java script program to perform string manipulation
function

AIM:

To write a java script program to perform string manipulation function.

ALGORITHM:

 OpenNotepad
 Typethejavascriptprogramforstringmanipulation.
 Savethefilewith.htmlasextension.
 Openthehtml fileinbrowser.
 Displaytheoutput.
 Stop.

PROGRAM:

STRING LENGTH

<html >

<head>

String Length

</head>

<body>

<p>The length property returns the length of the String is</p>

<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>Extracting String Parts</p>

<p id="demo"></p>

<script>

let str = "Apple, Banana, kiwi"; document.getElementById("demo").innerHTML= str.substr(7,6);

// let substring = str.substring(7,6);

// console.log(substring);

</script>

</body>

</html>

14
STRING SLICE

<html>

<head>

String Slice

</head>

<body>

<p>Extracting String Parts</p>

<p id="demo"></p>

<script>

let str="Apple, Banana, Kiwi"; document.getElementById("demo").innerHTML= str.slice(7,13);

</script>

</body>

</html>

STRING REPLACEMENT

<html >

<head>

</head>

<body>

<p>Replace Microsoft with MGR</p>

15
<button onclick="myFunction()">Try it</button>

<p id="demo">Please visit Microsoft</p>

<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;

use CGI':standard'; my $ampm;

my($sec,$min,$hour)=localtime(); print header;

print start_html(-bgcolor=>"orange"); print h1("THE DIGITAL CLOCK");

print "<META HTTP-EQUIV='Refresh' CONTENT='1'>";

if($hour>12)

$hour=$hour-12;
18
$ampm="PM";

else

$ampm="AM";

print h2("$hour:$min:$sec:$ampm"); print end_html( );

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:

#!"C:\xampp\perl\bin\perl.exe" use CGI':standard';

@msgs=("Welcome " ,"have a nice day","hi","how are you");

[email protected];

$n = int(rand($len)); if (param)

print header( );

print start_html(-bgcolor=>"pink");

$name=param("name"); print b("Hello $name

$msgs[$n]"),br(); print start_form(); print submit(-


20
value=>"Back"); print end_form();

print end_html();

else

print header();

print start_html(-bgcolor=>"pink", -text =>"blue"); print start_form();

print b("Enter user name ");

print textfield(- name=>"name"),br(); print submit(-value =>"submit"); print end_form();

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:

#!"C:\xampp\perl\bin\perl.exe" print "content-type: text/html \n\n"; open (FILE, "<visit.txt");

$count=<FILE>;

close(FILE); open(FILE, ">visit.txt");

$count++;

print FILE "$count"; close(FILE);

23
print "<center><h1>You are the visitor number $count";

HTML code

<html>

<body bgcolor="pink">

<center>

<hr>

<h1>Display the number of visitors</h2><hr>

<form action="/cgi-bin/Lab6b.cgi">

<br><input type="submit" value="OK"><br></center>

</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:

#!"C:\xampp\perl\bin\perl.exe" use strict;

use CGI':standard'; print header(),

start_html(-bgcolor=>"pink"), hr(), h2("Server Information"), hr(),

"Server Name : $ENV{SERVER_NAME}", hr(),

"Server Protocol : $ENV{SERVER_SOFTWARE}", hr(), "Server Port : $ENV{SERVER_PORT}", hr(),

"CGI Revision : $ENV{GATEWAY_INTERFACE}"

25
hr(),

"Script Name : $ENV{SCRIPT_NAME}", hr(),

"Root Document : $ENV{DOCUMENT_ROOT}", end_html()

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

A. Processor Information and


B. Memory Information From/ ProcFiles.

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:

# initialize the amount variablemarks=10000


# perform division with 0a=marks/0
print(a)
OUTPUT:

37
CONTENT BEYOND SYLLABUS

Java script program to print screen information

AIM:

To write a javascript program to print screen information.

ALGORITHM:

 Open your notepad.


 Write a html code for perform screen information.
 Save the code with .htm as extension
 Open the file with browser and it displays the screen information

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:

To write a javascript program to create an animation.

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

width: 400px; height: 400px; position: relative; background: yellow;

#animate { width: 50px; height: 50px;

position: absolute; background-color: red;

40
</style>

<body>

<p><button onclick="myMove()">Click Me</button></p>

<div id ="container">

<div id ="animate"></div>

</div>

<script>

function myMove() { let id = null;

const elem = document.getElementById("animate"); let pos = 0;

clearInterval(id);

id = setInterval(frame, 5); function frame() {

if (pos == 350) { clearInterval(id);

} else { pos++;

elem.style.top = pos + "px"; elem.style.left = pos + "px";

</script>

</body></html>

41
OUTPUT:

Prepared by Reviewed by Approved by

42
43

You might also like