0% found this document useful (0 votes)
7 views24 pages

Javascript File

The document is a practical file for a Web Application course focusing on JavaScript and HTML, certifying the completion of the project under the guidance of a teacher. It includes acknowledgments, a series of JavaScript programming questions with corresponding solutions, and various functions demonstrating JavaScript capabilities. The content covers topics such as grade assignment, basic arithmetic operations, factorial calculation, and string manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

Javascript File

The document is a practical file for a Web Application course focusing on JavaScript and HTML, certifying the completion of the project under the guidance of a teacher. It includes acknowledgments, a series of JavaScript programming questions with corresponding solutions, and various functions demonstrating JavaScript capabilities. The content covers topics such as grade assignment, basic arithmetic operations, factorial calculation, and string manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

JAVASCRIPT HANDWRITTEN FILE

Name - ………………………………..

Class - ………………………………..

Board Roll No. ………………………………..

Subject- ………………………………..

Subject Code ………………………………..

Session ………………………………..

Subject Teacher ………………………………..

School Name ………………………………..

………………………………..
CERTIFICATE

This is to certify that ……………………of class XII


…………… (2025-2026) has successfully completed the
Web Application Practical File on JavaScript with Html
under the guidance of Mrs. Divya Chauhan as per the
guidelines of Central Board of Secondary Education, New
Delhi.

INTERNAL EXAMINER PRINCIPAL EXTERNAL EXAMINER


ACKNOWLEDGEMENT
I would like to express my profound gratitude towards many
individuals, as without their kind support it would not be
possible for me to complete this practical file report. I would
like to extend my sincere thanks to my respected teacher Mrs.
Divya Chauhan who gave me the golden opportunity in
enhancing my hidden capabilities.
Unfortunately, I addressed several difficulties in coordinating
the modules of the project but I am highly indebted to Mrs.
Divya Chauhan for her guidance and constant supervision as
well as for providing necessary information regarding the
Project and also for their support in completing this file
I would like to express my gratitude towards my principal ma’am
Mrs. Jyoti Wanchoo and my parents for their kind co-operation
and encouragement as they help me a lot in completing this
project.
I would like if you appreciate the quality and performance of
this work
At last, I end up by thanking all who helped me a lot in finalizing
the project within the limited time frame.
JavaScript File questions
Q1: Write a JavaScript Program by using function display() which is
used to assign different grades to students based on their scores.
 If a student scores above 90, assign grade A.
 If a student scores above 75, assign grade B.
 If a student scores above 65, assign grade C.
Ans:
Output:
Q2: Write a JavaScript Program by using function calculator( ) used to
take two numbers and one operator from user. Function will behave as
per the given condition on the basis of the inputted operator .
 Add two numbers if user enters ‘+’
 Subtract two number if user enters ‘-’
 Multiply two numbers if user enters ‘*’
 Division of two numbers if user enters ‘/’
Ans:
Output:
Q3: Write a JavaScript Program by using function factorial( ) used to
calculate the factorial of a number.
 The factorial of a non-negative integer n is the product of all positive integers less
than or equal to n.
 For example, the factorial of 3 is 3 * 2 * 1 = 6.
Ans:

Output
Q4: Write a JavaScript Program by using function print( ) first five
natural numbers by using while loop.
Ans:

Output:
Q5: Write a JavaScript Program by using function odd( ) used to display
odd numbers upto the specified limit entered by the user.
Ans:

Output:
Q6: Write a JavaScript Program by using function to find the sum of
positive numbers the while loop runs infinitely loop terminates only when user
enters a negative number.
Ans:
Q7: Write a JavaScript Program by using function table( ) used to display
table of a number entered by the user.
Ans:

Output:
Q8: Write a JavaScript Program by using function leap( ) used to check
the inputted year is a leap year or not. A year is a leap year if the following
conditions are satisfied:
 The year is a multiple of 400.
 The year is a multiple of 4 and not a multiple of 100.
Ans:

Output:
Q9: Write a JavaScript Program by using function used to convert first
letter of the entered string into capital letter.
Ans:

Output:
Q10 : Write a program to accept a number from the user. Based on the choice ‘S’ or ‘C’
entered by the user, calculate and display:
i. Square of the number
ii. Cube of the number
Ans:

Output:
Javascript File questions
Q11: Declare a function convert(a,b) in JavaScript to accept two strings arguments. The
function should convert first string in lowercase and second string in uppercase.
Ans:
<html>
<body>
<script>
function convert(a,b)
{
document.write(a.toLowerCase()+"<br>")
document.write(b.toUpperCase()+"<br>")
}
var a=prompt("enter 1 string")
var b=prompt("enter 2 string")
</script>
<button type="button" onclick='convert(a,b)'>Click Me!</button>
</body>
</html>

Output:
Q 12: Declare a function ‘stringsjava’ in JavaScript to accept two strings arguments.
a. Convert both the strings to Uppercase
b. Search for string1 in string2 and display the string if found.
c. Replace all occurrences of letter ‘i’ with ‘ # ‘ in string2.
d. Display first character of string1.

Ans:
<html>
<body>
<script>
function convert(a,b)
{
document.write(a.toUpperCase()+"<br>")
document.write(a.match(b)+"<br>")
document.write(b.toLowerCase()+"<br>")
document.write(b.replaceAll('i','#')+"<br>")
document.write(b.charAt()+"<br>")
}
var a=prompt("enter 1 string")
var b=prompt("enter 2 string")
</script>
<button type="button" onclick='convert(a,b)'>Click Me!</button>
</body>
</html>
Q 13: Write a JavaScript program used to create a function len_words(s),
accept a string argument and find the sum of length of the words and display
it as follows:
Input: ‘Genius is one percent inspiration, 99% perspiration
Output:
Genius 6
is 2
one 3
percent 7
inspiration, 12
99% 3
perspiration 13
sum of length of the words= 46

Ans:
<html>
<body>
<script>
function len_words(s)
{
var sum=0
for (i=0;i<s.length;i++)
{
if(s[i]!=' ')
{
document.write(s[i]+ ‘ ‘+ s[i].length);
sum=sum+s[i].length
}
else
{
document.write("<br>")
}
document.write(“sum of length of the words”+sum)
}
var str=prompt("enter a sentence")
</script>
<button type="button" onclick='len_words(s)'>Click Me!</button>
</body>
</html>
Q 14. Write a JavaScript program used to create a function display( ) in
which consider the following array:
var cars = ["Honda", "BMW", "Audi", “Porsche”];
and the defined function is ued to do the following tasks:
a. add an item “Volvo “ to the array cars in the last.
b. remove first element from the array.
c. display number of elements in the array.
d. add following array to an array “cars”.
var person=[“Rajan”, “Yagya”, “Munish”];
Solution:
<html>
<body>
<script>
function display( )
{
var cars = ["Honda", "BMW", "Audi", "Porsche"];
var person=["Rajan", "Yagya", "Munish"];
value=prompt("Enter the name of person")
cars.push(value)
document.write(cars+"<br>")
first_ele=cars.shift()
document.write("Removed Element"+first_ele+"<br>")
document.write("After removing first element from the array"+cars+"<br>")
document.write("Display number of elements in the array"+cars.length+"<br>")
var new_array=cars.concat(person)
document.write("New Array after concatenation"+new_array)
}
</script>
<form>
<input type="button" onclick="display()" value="submit">
</form>
</body></html>

Q15. Write a JavaScript program to find the sum of squares of a all the
elements.
Ans:
<html>
<body>
<script>
function sum_sq(array)
{
var sum = 0,
i = array.length;
while (i--)
{
sum += Math.pow(array[i], 2);
}
return sum;
}
sum_sq([0, 1, 2, 3, 4])
</script>
</body>
</html>

Q 16. Write a function:


a. To find the value of a number raised power another number using Math
object method.
b. To find the sqrt of a number using Math object method.
Solution:
<html>
<body>
<script>
function calculate( )
{
base=parseInt(prompt("Enter a number"))
exponent=parseInt(prompt("Enter a number"))
document.write(Math.pow(base,exponent)+"<br>")
no=parseInt(prompt("Enter a number"))
document.write(Math.sqrt(no))
}
</script>
<form>
<input type="button" onclick="calculate()" value="submit">
</form>
</body>
</html>

Q17: Write a JavaScript program to create a function fun( ) and call that function by using
event onload.
Ans:
<html>
<head>
<script>
function fun() {
alert("Hello World!!, Welcome to the javaTpoint.com");
}
</script>
</head>
<body onload = "fun()">
<h1> Example of the HTML onload attribute </h1>
<p> Try to refresh the document to see the effect. </p>
</body>
</html>

Output:

Q18: Write a JavaScript program to create a function fun( ) and call that function by using
event onmouseover .
Ans:
<html>
<head>
<script>
// this function will execute when onmouseover is triggered
function func()
{
// an alert will pop-up when onmouseover gets triggered
alert("onmouseover alert.");
}
</script>
</head>
<body>
<!-- creating an onmouseover event for a <b> tag-->
<b onmouseover = "func()">
Bring the cursor here to get an alert.
</b>
</body>
</html>

Q19: Java script program used to create a function that popups a message
when a key is pressed:
Ans:
<html>
<head>
<script>
<!--
function myFunction() {
alert("hey…you pressed a key now.")
}
//-->
</script>
</head>
<body>
<input type = "text" onkeydown = " myFunction()">
</body>
</html>

Output:

Q20: Java script program used to create a function that changed the color of
the text when the focus has been shifted.
Ans:
<html> <body>
<input type="text" id="id_1" onChange="show()">
<script>
function show(){
var x=document.getElementById('id_1');
x.style.color='red';
}
</script> </body> </html>

Output:

You might also like