Note:
Every program along with question should be written on a new page.
Write outputs on the blank page
Mention page number and date of experiment on every page.
Fill the index as given below
INDEX
sno Name Date of Date of
Experiment Submission
1 A program to add 2 numbers using function 03/07/2026 30/07/2026
2 A program to display a message using function 09/07/2026 30/07/2026
3 A program to find sum of first 10 even 15/07/2026 30/07/2026
numbers using function
4 A program to display if a number is positive 21/07/2026 30/07/2026
or negative using function
5 A program to display length and any 05/08/2026 15/08/2026
character in a string
6 Converting string in uppercase and lowercase 05/08/2026 15/08/2026
7 Searching and Finding Substrings in strings. 05/08/2026 15/08/2026
8 Extracting Substrings and modifying strings 05/08/2026 15/08/2026
9 Adding elements at the start and end of an 25/08/2026 28/08/2026
array
10 Removing first and last elements of an array 25/08/2026 28/08/2026
11 Display length and element on any index of an 25/08/2026 28/08/2026
array
12 Sorting array and displaying array in reverse 25/08/2026 28/08/2026
order
13 Round off a number 05/09/2026 08/09/2026
14 Using ceil and floor functions 05/09/2026 08/09/2026
15 Calculate power of a number 05/09/2026 08/09/2026
16 Display minimum and maximum value of an 05/09/2026 08/09/2026
array
17 Working of onload event 17/09/2026 25/09/2026
18 Working of onclick event 17/09/2026 25/09/2026
1. Write a program to input 2 numbers a display their sum using function.
<html><head><title>Addition</title></head>
<body>
<script type="text/javascript">
var num1=parseInt(prompt("Enter first number"));
var num2=parseInt(prompt("Enter second number"));
function add(a,b)
{
s=a+b;
[Link]("sum is"+s);
}
add(num1,num2);
</script></body></html>
OUTPUT (Suppose numbers are is 15 and 45)
sum is60
2. Write a program to enter name of a person and display a welcome message using function.
<html><head><title>Message</title></head>
<body>
<script type="text/javascript">
name=prompt("enter your name");
function msg(nm)
{
[Link]("Welcome "+nm+" to JavaScript");
}
msg(name);
</script></body></html>
Output:
Welcome GAURAV to JavaScript
3. Write a program to find the sum of first ten even numbers using function.
<html><head><title>Even numbers</title></head>
<body>
<script type="text/javascript">
var sum=0;
function even()
{
for(var i=2;i<=20;i=i+2)
{
sum=sum+i;
}
return(sum);
}
var s= even();
[Link]("Sum of first 10 even numbers is"+s);
</script></body></html>
OUTPUT
Sum of first 10 even numbers is 110
4. Write a program to display if a number is positive or negative using function.
<html><head><title>Type of number</title></head>
<body>
<script type="text/javascript">
var num=parseInt(prompt("Enter any number"));
function find(n)
{
if(n>0)
{
[Link](n+" It is a positive number");
}
else
{
[Link](n+" It is a negative number");
}}
find(num);
</script></body></html>
OUTPUT (Suppose number is 67) 67
It is a positive number
5. Write a program to input a string and perform the following:
(i) display the length of the string
(ii) input any number and display the character present on that index
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var str=prompt("Enter any string");
var num=parseInt(prompt("Enter any number"));
var l =[Link];
[Link]("Length of given string is "+l);
if(num<l)
{
[Link]("<br>Character present at position "+num+" is :-"+[Link](num));}
else
{
[Link]("<br>index is out of range");
}
</script></body></html>
OUTPUT (Assume string is “Welcome to JAVA”)
Length of given string is 15
Character present at position 6 is :-e
6. Write a program to input a string and perform the following:
(i) display the string in uppercase
(ii) display the string in lowercase
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var str=prompt("Enter any string");
[Link]("<br>String in uppercase is:-"+[Link]());
[Link]("<br>String in lowercase is:-"+[Link]());
</script></body></html>
OUTPUT
String in uppercase is:-WELCOME TO JAVA String in
lowercase is:-welcome to java
7. Write a program to input a string and perform the following:
rd
(i) display 5 characters from 3 position
(ii) input another string and search it in the original string
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var str=prompt("Enter any string");
var str1=prompt("Enter string to search");
[Link]("5 characters from 3rd position:-"+[Link](3,8));
if([Link](str1))
{
[Link]("<br>It exists in the original string");} else
{
[Link]("<br>It does not exists in the original string");
}
</script></body></html>
OUTPUT (Assume string is “Welcome to JAVA”)
5 characters from 3rd position:-come
It exists in the original string
8. Write a program to store a string “Hello World! Welcome to JAVA.” and perform the
following:
(i) Replace “JAVA” with “Java Script”.
(ii) The string should start with “Namaste!”
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var str="Hello World!Welcome to JAVA";
var str2="Namaste!";
[Link]("<br>Original string is:-"+str);
str=[Link]("JAVA","Java Script")
[Link]("<br>After replacement:-"+str);
[Link]("<br>After adding another string:-"+[Link](str));
</script></body></html>
OUTPUT
Original string is:-Hello World!Welcome to JAVA
After replacement:-Hello World!Welcome to Java Script
After adding another string:-Namaste!Hello World!Welcome to Java Script
9. Write a program to create an array with values “eat”, “sleep” and perform the following:
(i) Add value “exercise” at the end of array
(ii) Add value “work” at the beginning of array
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var ar=["eat","sleep"];
[Link]("Original Array is:"+ar); [Link]("exercise");
[Link]("<br>After adding value at the end:-"+ar);
[Link]("work");
[Link]("<br>After adding value at the start:-"+ar);
</script></body></html>
OUTPUT
Original Array is:eat,sleep
After adding value at the end:-eat,sleep,exercise
After adding value at the start:-work,eat,sleep,exercise
10. Write a program to create an array using new method with values “red”, “green”, “blue”,
“yellow” and perform the following:
(i) Remove the last element of array
(ii) Remove the first element of array
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var ar=new Array("red","blue","green","yellow");
[Link]("Original Array is:"+ar);
[Link]("exercise");
[Link]("<br>After removing value at the end:-"+ar);
[Link]("work");
[Link]("<br>After removing value at the start:-"+ar);
</script></body></html>
OUTPUT
Original Array is:red,blue,green,yellow
After removing value at the end:-red,blue,green
After removing value at the start:-blue,green
11. Write a program to create an array with values “red”, “green”, “blue”, “yellow” and perform
the following:
(i) Display length of the array
(ii) input any number and display value at that index
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var ar=["red","blue","green","yellow"];
[Link]("Original Array is:"+ar);
var l=[Link];
[Link]("<br>Length of array is:-"+l);
var i=parseInt(prompt("Enter any number"));
if(i<l)
{
[Link]("<br>value at index "+i+"is:-"+ar[i]);
}
else
{
[Link]("<br>index out of range");
} </script></body></html>
OUTPUT
Original Array is:red,blue,green,yellow Length of array
is:-4
value at index 3 is:-yellow
12. Write a program to create an array with values “red”, “green”, “blue”, “yellow” and perform
the following: (i) Sort the array
(ii) Display array elements in reverse order
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var ar=["red","blue","green","yellow"];
[Link]("Original Array is:"+ar);
[Link]();
[Link]("<br>In reverse order:-"+ar);
[Link]();
[Link]("<br>after sorting:-"+ar);
</script></body></html>
OUTPUT
Original Array is:red,blue,green,yellow In reverse
order:-yellow,green,blue,red after sorting:-
blue,green,red,yellow
13. Write a program to input any floating point number and display it after rounding off.
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var no=parseFloat(prompt("Enter any floating point number"));
[Link]("<br> Original number is:"+no);
no=[Link](no);
[Link]("<br> After rounding off:"+no);
</script></body></html>
OUTPUT
Original number is:23.45
After rounding off:23
14. Write a program to input any floating point number and display
(i) integer greater than or equal to the given number (ii)
integer smaller than or equal to the given number
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var no=parseFloat(prompt("Enter any floating point number"));
[Link]("<br> original number is:"+no);
[Link]("<br> integer greater than or equal to the given number:"+[Link](no));
[Link]("<br> integer smaller than or equal to the given number:"+[Link](no));
</script></body></html>
OUTPUT
original number is:23.67
integer greater than or equal to the given number:24
integer smaller than or equal to the given number:23
15. Write a program to calculate power of any number
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
var no=parseInt(prompt("Enter base"));
var no1=parseInt(prompt("Enter power"));
[Link]("<br> power is:"+[Link](no,no1));
</script></body></html>
OUTPUT(if no=2 and no1=5)
power is:32
16. Write a program to display minimum and maximum value of any five numbers.
<html><head><title>String</title></head>
<body>
<script type="text/javascript">
[Link]("<br> maximum value is:"+[Link](23,1,4,5,6,78));
[Link]("<br> m
inimum value is:"+[Link](23,1,4,5,6,78));
</script></body></html>
OUTPUT maximum value is:78
minimum value is:1
17. Write a program to display a message “hello” on page load event.
<html><head><title>String</title></head>
<body onload="load()">
<h1>Java Script Events</h1>
<h2>ONLOAD Event</h2>
<script type="text/javascript">
function load()
{
alert("Hello");
}
</script></body></html>
OUTPUT
18. Write a program to create a button show time. It should display current date and time upon
clicking on.
<html><head><title>String</title></head>
<body>
<h1>Java Script Events</h1>
<h2>CLICK Event</h2>
<input type="button" value="show time" onclick="show()">
<p id="demo"></p>
<script type="text/javascript">
function show()
{
[Link]("demo").innerHTML=Date();
}
</script></body></html>
Output