CSS EPA Solution-1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 87

Examination Paper Analysis

Top Summer-23 Winter-22 Summer-22


ic Name of Topic
No. Question Marks Question Marks Question Marks
1.(a) 2 1.(a) 2 1.(a) 2
1.(b) 2 1.(b) 2 1.(c) 2
1.(c) 2 1.(c) 2 2.(a) 4
Basics of JavaScript 2.(a) 4 1.(e) 2 4.(a) 4
1
Programming 2.(b) 4 5.(a) 6
2.(c) 4
Total 18 8 18
1.(d) 2 1.(d) 2 2.(b) 4
1.(e) 2 2.(a) 4 4.(b) 4
2.(d) 4 2.(b) 4 5.(b) 6
3.(a) 4 2.(c) 4 6.(c) 6
2 Array, Function and String 3.(b) 4 2.(d) 4
3.(c) 4 3.(a) 4
3.(b) 4
3.(c) 4
Total 20 30 20
1.(f) 2 1.(f) 2 1.(d) 2
5.(a) 6 5.(a) 6 1.(e) 2
3 Form and Event Handling 5.(b) 6 6.(a) 6 2.(c) 4
6.(a) 6 3.(c) 4
Total 20 14 14
4 Cookies and Browser Data 3.(d) 4 1.(g) 2 1.(b) 2
4.(c) 4 1.(e) 2
5.(a) 6 1.(g) 2
5.(b) 6 2.(d) 4
3.(a) 4
Examination Paper Analysis

6.(a) 6
Total 4 18 20
3.(d) 4 3.(d) 4
4.(d) 4
4.(a) 4 4.(c) 4
5.(c) 6
Regular Expression, Rollover 4.(d) 4 4.(d) 4
5 6.(b) 6
and Frames 5.(c) 6 6.(b) 6
Total 16 18 18
4.(b) 4 4.(b) 4 1.(f) 2
4.(c) 4 4.(e) 4 3.(b) 4
Menus,navigation and web 4.(e) 4 6.(b) 6 4.(e) 4
6
page protection 6.(c) 6 6.(c) 6 5.(c) 6

Total 18 20 16

Exam Unit No Question no as per MSBTE paper Marks


Year and Name

Summ Unit 1 1.(a) State the ways to display the output in JavaScript 2
er- Basics of 1.(b) List the logical operators in JavaScript with description 2
2023 JavaScript 1.(c) Write JavaScript to create object “student”with properties roll 2
Programmi number ,name,branch,year,Delete branch property and display remaining properties of
ng
student object. 4
2.(a) Explain getter and setter properties in JavaScript with suitable example. 4
2.(b) Explain Object creation in JavaScript using ‘new’ keyword with adding properties
and methods with example 4
2.(c) Write a JavaScript for loop that will iterate from 1 to 15. For each iteration it will
check if the current number is obb or even and display a message to the screen
Sample Output:
“1 is odd”
“2 is even”
Examination Paper Analysis

….............
…....
Winter Unit 1 1.(a) State the use of method in JavaScript with the help of suitable example. 2
-2022 Basics of 1.(b) List & explain datatypes in JavaScript 2
JavaScript 1.(c) Write a simple calculator program using switch case in JavaScript. 2
Programmi 1.(e) Describe property Getters & Setter. 2
ng
Summ Unit 1 1.(a) State the features of JavaScript. 2
er- Basics of 1.(c) Write a JavaScript program to check whether entered number is prime or not. 2
2022 JavaScript 2.(a) Write a JavaScript program to validate user accounts for multiple set of user 4
Programmi ID and password (using switch case statement).
ng
4.(a) Differentiate between For-loop and For-in loop. 4
5.(a) Write a JavaScript to checks whether a passed string is palindrome or not. 4
Summ Unit 2 1.(d) Write JavaScript that initializes an array called Colors with the names of 3 Colors 2
er- Array, and display array elements.
2023 Function 1.(e) Explain calling a function with arguments in JavaScript with example. 2
and String 2.(d) Write the use of charCodeAt() and from CharCode() method with syntax and 4
example 4
3.(a) Differentiate between push() and join() method of array object with respect to
use,syntax,return value and example. 4
3.(b) Write a Javascript code to perform following operation on string (Use split()
method)
Input string : Sudha Narayana Murthy”
Display output as
First Name:Sudha
Middle Name: Narayana 4
Last Name: Murthy
3.(c) Explain splice() method of array object with syntax and example.
Winter Unit 2 1.(d) Write a program using sort method of array object. 2
-2022 Array, 2.(a) Write a JavaScript program that will display current date in DD/MM/YYYY 4
Function format.
and String 2.(b) Write a JavaScript program that will remove the duplicate element from an 4
Array.
(c) Write a JavaScript program that will display list of student in ascending order 4
according to the marks & calculate the average performance of the class.
Examination Paper Analysis

2.(d) Write and explain a string functions for converting string to number and 4
number to string.
3.(a) Differentiate between concat( ) & join( ) methods of array object. 4
3.(b) Write a JavaScript function to check the first character of a string is uppercase 4
or not.
3.(c) Write a JavaScript function to merge two array & removes all duplicate
values. 4
Summ Unit 2 2.(b) Differentiate between concat() and join() methods of array object. 4
er- Array, 4.(b) Write a javascript function that accepts a string as a parameter and find the 4
2022 Function length of the string.
and String 5.(b) Develop javascript to convert the given character to unicode and vice-versa. 6
6.(c) Write a javascript function to generate Fibonacci series till user defined limit.

Summ Unit 3 1.(f) Enlist any four mouse events with their use. 2
er- Form and 5.(a) Write HTML code to design a form that display two textboxes for accepting two 6
2023 Event numbers,one textbox for accepting result and two buttons as ADDITION and
Handling SUBTRACTION.Write proper JavaScript such that when the user clicks on any one of the
button,respective operation will be performed on two numbers and result will be
displayed in result textbox. 6
5.(b) Write HTML code to design a form that dsiplayes two buttons START and
STOP.Write a JavaScript code such that when user clicks on START button, real time
digital clock will be displayed on screen. When user clicks on STOP button,clock will 6
stop displaying time(Use Timer Methods)
6.(a) Explain how to evaluate Radiobutton in JavaScript with suitable example.
Winter Unit 3 1.(f) Enlist & explain the use of any two Intrinsic JavaScript functions. 2
Examination Paper Analysis
-2022 Form and 6
Event 5.(a) Write HTML script that will display following structure
Handling

Write the JavaScript code for below operations :


(1) Name, Email & Pin Code should not be blank.
(2) Pin Code must contain 6 digits & it should not be accept any characters.

6.(a) Write HTML script that will display dropdown list containing options such as
Red, Green, Blue & Yellow. Write a JavaScript program such that when the 6
user selects any options. It will change the background colour of webpage.
Summ Unit 3 1.(d) Explain following form events : 2
er- Form and (i) onmouseup
2022 Event (ii) onblur
Handling 1.(e) Write a javascript program to changing the contents of a window. 2
2.(c) Write a javascript program to demonstrate java intrinsic function. 4
3.(c) Write a javascript program to calculate add, sub, multiplication and division
of two number (input from user). Form should contain two text boxes to input 4
numbers of four buttons for addition, subtraction, multiplication and division.
Summ Unit 4 Q3 d. Explain how to create and read Persistent Cookies in JavaScript with example. 4
er-
2023
Winter Unit 4 Q1 g. Describe browser location object. 2
-2022 Q5 a. Write HTML script that will display following structure 6
6
Examination Paper Analysis

Write the JavaScript code for below operations : (1) Name, Email & Pin Code should not be
blank. (2) Pin Code must contain 6 digits & it should not be accept any characters.
Q5 b. Write a webpage that displays a form that contains an input for username & password.
User is prompted to entre the input & password & password becomes the value of the cookie.
Write a JavaScript function for storing the cookie. It gets executed when the password changes.
Summ Unit 4 Q1 b. Differentiate between session cookies and persistent cookies. 2
er- Q1 e. Write a JavaScript program to changing the contents of a window. 2
2022 Q1 g. Write a JavaScript syntax to accessing elements of another child window. 2
Q2 d. Design a webpage that displays a form that contains an input for user name and 4
password. User is prompted to enter the input user name and password and password become 4
value of the cookies. Write the JavaScript function for storing the cookies. 6
Q3 a. Write a JavaScript program to create read, update and delete cookies.
Q6 a. Write a JavaScript to open a new window and the new window is having two frames. One
frame containing button as “click here !”, and after clicking this button an image should open in
the second frame of that child window.
Summ Unit 5 Q4 d. Explain text and image rollover with suitable example. 2
er- Q5 c. Write HTML code to design a form that displays textboxes for accepting UserID and 6
2023 Aadhar No. and a SUBMIT button. UserlD should contain 10 alphanumeric characters and must 6
start with Capital Letter. Aadhar No. should contain 12 digits in the format nnnn nnnn nnnn.
Write JavaScript code to validate the UserID and Aadhar No. when the user clicks on SUBMIT
button.
Q6 b. Write a script for creating following frame structure : Frame 1 contains three buttons
SPORT, MUSIC and DANCE that will perform following action : When user clicks SPORT button,
sport.html webpage will appear in Frame 2. When user clicks MUSIC button, music.html
webpage will appear in Frame 3. When user clicks DANCE button, dance.html webpage will
appear in Frame 4.
Examination Paper Analysis

Winter Unit 5 Q3 d. Write a JavaScript function that will open new window when the user will clicks on the 4
-2022 button. 4
Q4 a. Describe text Rollover with the help of example. 4
Q4 c. Describe Quantifiers with the help of example. 4
Q4 d. Describe frameworks of JavaScript & its application. 6
Q5 c. Write a JavaScript for creating following frame structure :

Chapter 1 & Chapter 2 are linked to the webpage Ch1 HTML & Ch2.html respectively. When
user click on these links corresponding data appears in FRAME3.
Summ Unit 5 Q3 d. State what is regular expression. Explain its meaning with the help of a suitable example. 4
er- Q4 c. Write a JavaScript program to validate email ID of the user using regular expression. 4
2022 Q4 d. Write a JavaScript program to design HTML page with books information in tabular format, 4
use rollovers to display the discount information. 6
Q6 b. Write a JavaScript to create option list containing list of images and then display images in
new window as per selection.
Summ Unit 6 Q4 b. List Ways of protecting your web page and describe any one of them. 4
er- Q4 c. Explain how to create and display Rotating Banner in JavaScript with example. 4
2023 Q4 e. What is Status bar and how to display moving message on the status line of a window 4
using JavaScript. 6
Q6 c. Write a JavaScript to create a pull - down menu with four options [AICTE, DTE, MSBTE,
GO0GLE]. Once the user will select one of the options then user will be redirected to that site.
Examination Paper Analysis
Winter Unit 6 Q4 b. Write a JavaScript program that will create pull-down menu with three options. Once the 4
-2022 user will select the one of the options then user will redirected to that website. 4
Q4 e. Describe how to link banner advertisement to URL with example. 6
Q6 b. Develop a JavaScript program to create Rotating Banner Ads. 6
Q6 c. Write a JavaScript for the folding tree menu.
Summ Unit 6 Q1 f. Explain frame works of JavaScript and its application. 2
er- Q3 b. Write a JavaScript program to link banner advertisements to different URLs. 4
2022 Q4 e. List ways of protecting your webpage and describe any one of them. 6
Q5 c. Write a JavaScript program to create a slide show with the group of six images, also 6
simulate the next and previous transition between slides in your JavaScript.
Examination Paper Analysis

Exam Unit No Question no as per MSBTE paper Marks


Year and
Name
Summ Unit 1 1.(a) State the ways to display the output in JavaScript 2M
er- Basics of Ans:
2023 JavaScript one
Programm ● Writing into an HTML element, using innerHTML. way
ing ● Writing into the HTML output using document.write(). for ½
● Writing into an alert box, using window.alert(). mark
● Writing into the browser console, using console.log().

1.(b) List the logical operators in JavaScript with description 2M


Ans:
Any
Operator Description Example two
&& and (x < 10 && y > 1) is opera
true
tor
|| or (x == 5 || y == 5) is
false
1
! not !(x == y) is true mark
for
each
opera
tor
1.(c) Write JavaScript to create object “student”with properties roll 2M
number ,name,branch,year,Delete branch property and display remaining properties
of student object. Prope
r
Ans:
corre
<script>
var student ={ ct
roll_number:1001 logic
branch:”IF” progr
Examination Paper Analysis
year:First am 2
name:”XYZ” marks
document.write(student.roll_number+” ”+student.branch+” “ +
student.year+” “ +student.name);
delete student.branch;
document.write(student.roll_number+” ”+student.branch+” “ +
student.year+” “ +student.name);
</script>

2.(a) Explain getter and setter properties in JavaScript with suitable example. 4M
Ans:
Gette
JavaScript object accessors are used to access and update the objects. Getter and setter are r
used as object accessors to get or set object properties.
expla
Getter method helps in accessing the object methods as object properties.
Setter method is used to set object properties. natio
Using getter and setter the javascript provides better data security and data quality. n2
Example: mark
<!DOCTYPE html> Setter
<html> expla
<body> natio
<script> n2
var car = { marks
brand: "Toyota",
color: "Blue",
get getBrand () {
return this.brand;
},
get getColor () {
return this.color;
},
set setBrand (newBrand) {
this.brand = newBrand;
},
set setColor (newColor) {
this.color = newColor;
}
};
Examination Paper Analysis
document.write("Car Brand: " + car.brand + "<br>Car Color: " + car.color);
car.setBrand = "Tesla";
car.setColor = "Red";
document.write("<br><br>Car Brand: " + car.brand + "<br>Car Color: " + car.color);
</script>
</body>
</html>

2.(b) Explain Object creation in JavaScript using ‘new’ keyword with adding properties and 4M
methods with example
Ans: Objec
A javascript object is an entity having state and behavior. t
JavaScript is an object based language.
creati
There are three ways to create object:
1) By Object Literal on 2
mark
2) By creating instance of object directly
addin
3) By using an object constructor
g
prope
Example: rty
<script> and
var emp =new Object(); meth
emp.id=101; od 2
emp.name=””Yash Desai” mark
emp.salary=50000;
document.write(emp.id+” “ +emp.name+” “emp.salary”);
</script>
Examination Paper Analysis
2.(c) Write a JavaScript for loop that will iterate from 1 to 15. For each iteration it will 4M
check if the current number is obb or even and display a message to the screen
Sample Output: Corre
“1 is odd” ct
“2 is even”
logic
….............
….... progr
am 4
Ans: marks

<script>
for(var i=1; i<=15; i++)
{
if(i%2)
{
document.write(i+”is even”);
}
else
{
document.write(i+”is odd”);
}
}
</script>
Examination Paper Analysis
Winter Unit 1 1.(a) State the use of method in JavaScript with the help of suitable example. 2M
-2022 Basics of Ans:
JavaScript Expla
Programm A method/function is a set of statements that take inputs, do some specific computation, and natio
ing produce output. The idea is to put some commonly or repeatedly done tasks together and make
n1M
a function so that instead of writing the same code again and again for different inputs, we can
call that function. and
Example: exam
function Addition (number1, number2) ple 1
{ M
return number1 + number2;
}
Examination Paper Analysis
1.(b) List & explain datatypes in JavaScript 2M
Ans:
Listin
JavaScript provides different data types to hold different types of values. There are two types of g1M
data types in JavaScript, Primitive data type and Non-primitive data type
and
i) There are five types of primitive data types in JavaScript. They are as follows: expla
String - represents sequence of characters e.g., "hello" natio
Number - represents numeric values e.g., 100 n1M
Boolean - represents boolean value either false or true
Undefined - represents undefined value
Null - represents null i.e., no value at all
ii) The non-primitive data types are as follows:
Object - represents instance through which we can access members
Array - represents group of similar values
RegExp - represents regular expression

1.(c) Write a simple calculator program using switch case in JavaScript. 2M


Ans:
Any
<html> correc
<body>
t logic
<script>
const number1 = parseFloat(prompt("Enter first number: ")); progra
const number2 = parseFloat(prompt("Enter second number: ")); m2
const operator = prompt("Enter operator ( either +, -, *, / or %): "); marks
let result;
switch (operator) {
case "+":
result = number1 + number2;
document.write(result);
Examination Paper Analysis
break;
case "-":
result = number1 - number2;
document.write(result);
break;
case "*":
result = number1 * number2;
document.write(result);
break;
case "/":
result = number1 / number2;
document.write(result);
break;
case "%":
result = number1 % number2;
document.write(result);
break;
default:
document.write("Invalid operator");
break;
}
</script>
</body>
</html>
1.(e) Describe property Getters & Setter. 2M
Ans:
Getter
JavaScript object accessors are used to access and update the objects. Getter and setter are 1 Mark
used as object accessors to get or set object properties.
and
Getter method helps in accessing the object methods as object properties.
Setter method is used to set object properties. Setter
Using getter and setter the javascript provides better data security and data quality. 1 Mark
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var car = {
Examination Paper Analysis
brand: "Toyota",
color: "Blue",
get getBrand () {
return this.brand;
},
get getColor () {
return this.color;
},
set setBrand (newBrand) {
this.brand = newBrand;
},
set setColor (newColor) {
this.color = newColor;
}
};
document.write("Car Brand: " + car.brand + "<br>Car Color: " + car.color);
car.setBrand = "Tesla";
car.setColor = "Red";
document.write("<br><br>Car Brand: " + car.brand + "<br>Car Color: " + car.color);
</script>
</body>
</html>
Examination Paper Analysis
Summ Unit 1 1.(a) State the features of JavaScript. 2M
er- Basics of Ans:
2022 JavaScript Any
Programm 1) Lightweight four
ing JavaScript does not have too many language constructs. featur
JavaScript uses dynamic typing, so everything that you declare or assign, the e
interpreter tries to figure out, what should be the type of a certain variable.
One
2) Object-oriented
3) Interpreted based
featur
4) Handling date and Time e for
5) Validating user inputs ½
6) Event Handling marks
Examination Paper Analysis
1.(c) Write a JavaScript program to check whether entered number is prime or not. 2M
Ans:
<html> Proper
<body> correc
<script>
t logic
var i, chk=0;
var num = parseInt(prompt("Enter a positive number: ")); progra
for(i=2; i<num; i++) m2
{ Mark
if(num%2==0)
{
chk++;
break;
}
}
if(chk==0)
document.write(num + " is a Prime Number");
else
document.write(num + " is not a Prime Number");
</script>
</body>
</html>

2.(a) Write a JavaScript program to validate user accounts for multiple set of user 4M
ID and password (using switch case statement).
Ans: Any
proper
<html>
correc
<body>
Enter your User ID t logic
<input type="text" id="id"> progra
<br><br> m4M
Enter your Password
<input type="password" id="pass">
<br><br>
<input type="submit" onclick="check()">
Examination Paper Analysis
<br><br>
<p id="display"></p>
<script>
function check() {
var uid = document.getElementById('id').value;
var pass = document.getElementById('pass').value;
switch(uid){
case "[email protected]":
if(pass == "darshan@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
case "[email protected]":
if(pass == "prashant@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
case "[email protected]":
if(pass == "konisha@123"){
document.getElementById('display').innerHTML = "Valid User";
}
break;
default:
document.getElementById('display').innerHTML = "Invalid User";
}
}
</script>
</body>
</html>
4.(a) Differentiate between For-loop and For-in loop. 4M
Ans:
Any
For loop For-in loop four
for loop provides a concise way of writing the For-in loop in JavaScript is used to iterate points
loop structure. over the properties of an object.
of
For instance, if you want to iterate Certainly, for objects, the for-in loop
over even numbers, you'd need to use the allows you to get the property name in
differe
normal for loop the iteration variable. nce 1
Examination Paper Analysis

for (expr 1; expr 2; expr3) for (x in object) { point


{ code block to be executed one
// code block to be executed } mark
}
// program to display text 5 times <script>
const n = 5; var code= {
CO : "Comp Engg.",
// looping from i = 1 to 5 IF : "Info Tech",
for (let i = 1; i <= n; i++) { EJ : "Electronics"
console.log(`I love JavaScript.`); }
} // using for...in
for ( var i in code) {
var c= code[i];
// display the values
document.write(i+"="+c+"<br>");
}
</script>

5.(a) Write a JavaScript to checks whether a passed string is palindrome or not. 6M

Ans: Correc
<script> t logic
// program to check if the string is palindrome or not
progra
function checkPalindrome(string)
{ m6
// convert string to an array marks
const arrayValues = string.split('');
// reverse the array values
const reverseArrayValues = arrayValues.reverse();
// convert array to string
const reverseString = reverseArrayValues.join('');

if(string == reverseString) {
document.write('It is a palindrome');
}
else {
document.write('It is not a palindrome');
Examination Paper Analysis
}
}
//take input
const string = prompt('Enter a string: ');
checkPalindrome(string);
</script>

Summe Unit 2 1.(d) Write JavaScript that initializes an array called Colors with the names of 3 Colors and
r-2023 Array, display array elements. 2M
Function Ans:
and String <html lang="en"> Correc
t logic
<body>
<script> progra
// Creating variables m2
var colors = ["Red", "Green", "Blue"]; Marks

// Printing variable values


document.write(colors + "<br>");

</script>
</body>
</html>
Examination Paper Analysis
1.(e) Explain calling a function with arguments in JavaScript with example. 2M
Ans:
Each function definition contains a parameter list enclosed in the parenthesis. Explan
Syntax to declare the function along the parameter lists is: ation 1
Function function_name(parameter_list)
M
{
//Code to be excuted Examp
} le 1 M

Example:
<script>
function maxTwo(x,y)
{
if(x,y)
return x;
else
return y;
}
</script>

2.(d) Write the use of charCodeAt() and fromCharCode() method with syntax and example 4M
Ans:
charChodeAt(): 2M for
● The charCodeAt() method takes an integer as an argument that represents the index of charCo
the character in which you’re interested. If you don’t pass an argument, it defaults to deAt()
index 0.
● The charCodeAt() method returns the Unicode number of the string: 2M for
var UnicodeNum = StringName.charCodeAt() fromC
harCo
Example: de()
<script>
var x="Javatpoint";
Examination Paper Analysis
document.writeln(x.charCodeAt(3));
</script>

fromCharCode():
● If you need to know the character, number, or symbol that is assigned to a Unicode
number, use the fromCharCode() method. The fromCharCode() method requires one
argument, which is the Unicode number.
Example:

<html>
<body>
<script>

var res = String.fromCharCode(72, 69, 76, 76, 79);

document.write("<br>"+res1);
</script>
</body>
</html>

3.(a) Differentiate between push() and join() method of array object with respect to 4M
use,syntax,return value and example.
Ans: Any 4
point
relate
Push() Join()
d to
This method adds zero or more elements to Returns the new string by concatenating all of
the end of the array. the elements in an array separated by a syntax
specified character. ,
Syntax: arr.push(element1, element2,----); Syntax: arr.join(separator); return
Separator is an optional parameter. By default value
it is comma and
Returns the new length of the array after Returns the string with all the array elements examp
appending the new elements into the an joined by seperator le
array.
Example: Example”
<html> <html>
Examination Paper Analysis

<head> <body>
<title> Array</title> <script>
<body>
<script> var products = new Array();
var fruits = new Array(3); products[0] = 'Car ';
fruits[0] = "Banana"; products[1] = 'Water';
fruits[1] = "Orange"; products[2] = 'Soap';
fruits[2] = "Apple"; products[3] = 'Pizza';
fruits[3] = "Mango"; var str = products.concat();
for(i=0;i<fruits.length;i++) document.write(str);
{ document.write('<br>');
document.write(fruits[i] +" "+"<br>"); var str = products.join(' ');
} document.write(str);
fruits.push("Lemon"); </script>
for(i=0;i<fruits.length;i++) </body>
{ </html>
document.write(fruits[i] +" ");
}
</script>
</body>
</html>
Examination Paper Analysis
3.(b) Write a Javascript code to perform following operation on string (Use split() method) 4M
Input string : Sudha Narayana Murthy”
Display output as Any
First Name:Sudha correc
Middle Name: Narayana
t logic
Last Name: Murthy
progra
Ans: m4
<script> Marks
Var str=” Sudha Narayana Murth”
Var arr=str.spilt(“ “,3);
document.write(“First Name:+arr[0]+”<br”>
document.write(“Middle Name:+arr[1]+”<br”>
document.write(“Last Name:+arr[1]+”<br”>
</script>

3.(c) Explain splice() method of array object with syntax and example. 4M
Ans:
Explan
The splice() method can be used to add new items to an array, and removes elements from an ation 2
array.
marks
Syntax: arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added); Examp
Parameter: e2
•The first parameter defines the position where new elements should be added (spliced in). Marks
•The second parameter defines how many elements should be removed.
•The list_of_elemnts_to_be_added parameter define the new elements to be added(optional).

Output:
Examination Paper Analysis
<html>
<body>
<script>
var fruits = ["Banana", "Watermelon", "Chikoo", "Mango", "Orange", "Apple"];
document.write(fruits+"<br>");
fruits.splice(2,2, "Lemon", "Kiwi");
document.write(fruits+"<br>");
fruits.splice(0,2); //removes first 2 elements from array document.write(fruits+"<br>");
</script>
</body>
</html>

Output:
Banana,Watermelon,Chikoo,Mango,Orange,Apple Banana,Watermelon,Lemon,Kiwi,Orange,Apple
Lemon,Kiwi,Orange,Apple
Examination Paper Analysis
Winter Unit 2 1.(d) Write a program using sort method of array object. 2M
-2022 Array, Ans:
Function Correc
and String <html> t Logic
<body>
progra
<script>
var array =[5,1,9,7,5]; m2
// sorting the array Marks
sorted = array.sort();
document.write(sorted);
</script>
</body>
</html>
Examination Paper Analysis
2.(a) Write a JavaScript program that will display current date in DD/MM/YYYY 4M
format.
Ans: Correc
t logic
<!DOCTYPE html>
progra
<html lang="en">
<head> m4
<meta charset="UTF-8"> Marks
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var d=new Date();
var currentDate=d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear()
document.write(currentDate)
</script>
</body>
</html>
Examination Paper Analysis
2.(b) Write a JavaScript program that will remove the duplicate element from an 4M
Array.
Ans: Correc
t logic
<!DOCTYPE html>
progra
<html lang="en">
<body> m4
<script> Marks
let arr = ["scale", "happy", "strength", "peace", "happy", "happy"];
function removeDuplicates(arr) {
let unique = [];
for (i = 0; i < arr.length; i++) {
if (unique.indexOf(arr[i]) === -1) {
unique.push(arr[i]);
}
}
return unique;
}
document.write(removeDuplicates(arr));
</script>
</body>
</html>

2 (c) Write a JavaScript program that will display list of student in ascending order 4M
according to the marks & calculate the average performance of the class.
Correc
t
Progra
m4
Marks
Examination Paper Analysis

Ans:
<html>
<body>
<script>
var students = [["Amit", 70],["Sumit", 78],["Abhishek", 71],];
var Avgmarks = 0;
for (var i = 0; i < students.length; i++) {
Avgmarks += students[i][1];
for (var j = i + 1; j < students.length; j++) {
if (students[i] > students[j]) {
a = students[i];
students[i] = students[j];
students[j] = a
}
}
}
var avg = Avgmarks / students.length;
document.write("Average grade: " + Avgmarks / students.length);
document.write("<br><br>");
for (i = 0; i < students.length; ++i){
document.write(students[i]+"<br>")
}
</script>
</body>
</html>
Examination Paper Analysis
2.(d) Write and explain a string functions for converting string to number and
number to string.
Ans:
To covert string to number we can use parseInt() which converts a string number to a integer
number. Similarly we can use parseFloat(), number() for converting string to number.
Eg-
var a=prompt('Enter a number');
var b=parseInt(prompt('Enter a number'));
document.write(typeof a+"<br>");
document.write(typeof b);
To convert form number to string we can use toString()
<html>
<body>
<p>toString() returns a number as a string:</p>
<script>
let num = 12;
let text = num.toString();
document.write(num)
</script>
</body>
</html>
Examination Paper Analysis
3.(a) Differentiate between concat( ) & join( ) methods of array object. 4M
Ans:
Any 4
concat() of array object join() of array object points
The concat() method concatenates (joins) The join() method returns an array as a 4
two or more arrays. string. Marks
The concat() method does not change the The join() method does not change the
existing arrays. original array.
Syntax: Syntax: array.join(separator)
array1.concat(array2, array3, ..., arrayX) Any separator can be specified. The default
is comma (,).
Example: Example:
<script> <script>
var arr1 = ["Java", "Python"]; var fruits = ["Banana", "Orange", "Apple",
var arr2 = [1, 2, 3]; "Mango"];
var arr3 = arr1.concat(arr2); var text = fruits.join("#");
document.write(arr3); document.write(text);
</script> </script>

3.(b) Write a JavaScript function to check the first character of a string is uppercase 4M
or not.
Ans: Correc
t
<html>
Prgra
<body>
<script> m fro
function upper_case(str) 4
{ Marks
regexp = /^[A-Z]/;
Examination Paper Analysis
if (regexp.test(str))
{
document.write("String's first character is uppercase");
}
else
{
document.write("String's first character is not uppercase");
}
}
upper_case('Abcd');
</script>
</body>
</html>
OR
<script>
function firstIsUppercase(str)
{
if (str.length === 0)
{
return false;
}
return str.charAt(0).toUpperCase() === str.charAt(0);
}
if (firstIsUppercase(prompt("Enter text")))
{
document.write('First letter is uppercase');
} else {
document.write('First letter is NOT uppercase');
}
</script>

3.(c) Write a JavaScript function to merge two array & removes all duplicate
values.
Ans:
<html>
<body>
<script>
function merge_array(array1, array2)
Examination Paper Analysis
{
var result_array = [];
var arr = array1.concat(array2);
var len = arr.length;
var assoc = {};
while(len--)
{
var item = arr[len];
if(!assoc[item])
{
result_array.unshift(item);
assoc[item] = true;
}
}
return result_array;
}
var array1 = [1, 2, 3,4,7,9];
var array2 = [2, 30, 1,40,9];
document.write(merge_array(array1, array2));
</script>
</body>
</html>
Output:
3,4,7,2,30,1,40,9
OR
<html>
<body>
<script>
function mergearr(arr1, arr2)
{
// merge two arrays
var arr = arr1.concat(arr2);
var uniqueArr = [];
// loop through array
for(var i of arr) {
if(uniqueArr.indexOf(i) === -1)
{
uniqueArr.push(i);
Examination Paper Analysis
}
}
document.write(uniqueArr);
}
var array1 = [1, 2, 3,6,8];
var array2 = [2, 3, 5,56,78,3]
mergearr(array1, array2);
</script>
</body>
</html>
Output:
1,2,3,6,8,5,56,78
Summe Unit 2 2.(b) Differentiate between concat() and join() methods of array object.
r-2022 Array, Ans:
Function concat() of array object join() of array object
and String The concat() method concatenates (joins) The join() method returns an array as a
two or more arrays. string.
The concat() method does not change the The join() method does not change the
existing arrays. original array.
Syntax: Syntax: array.join(separator)
array1.concat(array2, array3, ..., arrayX) Any separator can be specified. The default
is comma (,).
Example: Example:
<script> <script>
var arr1 = ["Java", "Python"]; var fruits = ["Banana", "Orange", "Apple",
var arr2 = [1, 2, 3]; "Mango"];
var arr3 = arr1.concat(arr2); var text = fruits.join("#");
document.write(arr3); document.write(text);
</script> </script>

4.(b) Write a javascript function that accepts a string as a parameter and find the
length of the string.
Ans:
<html>
<body>
<p id="demo"></p>
<script>
Examination Paper Analysis
function len(text)
{
return (text.length);
}
document.getElementById("demo").innerHTML = "length of string="+len("Information");
</script>
</body>
</html>

Output:

5.(b) Develop javascript to convert the given character to unicode and vice-versa.
Ans:
<script>
var x="HeLLO";
document.writeln(x.charCodeAt(3));
document.writeln("<br>"+x.charCodeAt(1));
document.writeln("<br>"+x.charCodeAt(4));
document.writeln("<br>");
var res = String.fromCharCode(72, 69, 76, 76, 79);
document.write(res);
</script>

Output:

6.(c) Write a javascript function to generate Fibonacci series till user defined limit.
Ans:
<script>
Examination Paper Analysis
function fibonacci(num)
{
var x = 0;
var y = 1;
var z;
var i = 0;
document.write(x);
document.write("<br>"+y);
for (i = 2; i < num; i++)
{
z = x + y;
x = y;
y = z;
document.write("<br>"+y);
}
}
var num = parseInt(prompt('Enter the number of terms: '));
answer = fibonacci(num);
</script>

Summe Unit 3 1.(f) Enlist any four mouse events with their use. 2
r-2023 Form and Ans: 6
Event Onclick:
Handling Fires on a mouse click on the element
Ondblclick: Fires on a mouse double-click on the element
Onmousedown: Fires when a mouse button is pressed down on an element
Onmousemove: Fires when the mouse pointer is moving while it is over an element 6
Onmouseout: Fires when the mouse pointer moves out of an element
Onmouseover:Fires when the mouse pointer moves over an element
Onmouseup: Fires when a mouse button is released over an element 6
Onwheel: Fires when the mouse wheel rolls up or down over an element
Oncontextmenu:oncontextmenu event occurs when the user right-clicks on an element to open
the context menu.

5.(a) Write HTML code to design a form that display two textboxes for accepting two
numbers,one textbox for accepting result and two buttons as ADDITION and SUBTRACTION.Write
Examination Paper Analysis
proper JavaScript such that when the user clicks on any one of the button,respective operation
will be performed on two numbers and result will be displayed in result textbox.

5.(b) Write HTML code to design a form that dsiplayes two buttons START and STOP.Write a
JavaScript code such that when user clicks on START button, real time digital clock will be
displayed on screen. When user clicks on STOP button,clock will stop displaying time(Use Timer
Methods)

Ans:
<html>
<body>
<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<button onclick="clearInterval(myVar)">Stop time</button>
<script>
var myVar = setInterval(myTimer ,1000);
function myTimer()
{
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
</body>
</html>
6.(a) Explain how to evaluate Radiobutton in JavaScript with suitable example.

Ans:
The radio button allows the user to choose one of a predefined set of options. You can define
groups with the name property of the radio buttons.
Radio buttons with the same name belong to the same group. Radio buttons with different
names belongs to the different groups. At most one radio button can be checked in a group.
Syntax:
<input type="radio" id="male" name="gender" value="male">

Code:

<html>
Examination Paper Analysis
<body>
<form method="post" action=" " onsubmit="return ValidateForm();">
<fieldset>
<legend>Select Course:</legend>
<input type="radio" name="br" value="IT" checked>IT<br>
<input type="radio" name="br" value="CO">CO<br>
<input type="radio" name="br" value="EJ">EJ<br>
<br>
<input type="submit" value="Submit now">
</fieldset>
</form>
<script type="text/javascript">
function ValidateForm()
{
var obj = document.getElementsByName("br");
for(var i = 0; i < obj.length; i++)
{
if(obj[i].checked == true)
{
if(confirm("You have selected " + obj[i].value))
return true;
else
return false;
}
}
}
</script>
</body>
</html>
Winter- Unit 3 1.(f) Enlist & explain the use of any two Intrinsic JavaScript functions. 2
2022 Form and Ans: 6
Event An intrinsic function (or built-in function) is a function (subroutine) available for use in a given
Handling programming language whose implementation is handled specially by the compiler. You can use
intrinsic functions to make reference to a data item whose value is derived automatically during
execution.
abs() - The ABS function returns the absolute value of the argument.
sin() - The SIN function returns a numeric value that approximates the sine of the angle or arc
specified by the argument in radians.
Examination Paper Analysis
sqrt() - The SQRT function returns a numeric value that approximates the square root of the
argument specified.
Date(): return current date.
Len(): returns number of characters in the text.
parseInt() - parseInt() function takes string as a parameter and converts it to integer.
parseFloat() - parseFloat() function takes a string as parameter and parses it to a floating point
number.

5.(a) Write HTML script that will display following structure

Write the JavaScript code for below operations :


(1) Name, Email & Pin Code should not be blank.
(2) Pin Code must contain 6 digits & it should not be accept any characters.
Ans:
<html>
<head>
<style>
table,tr,td
{
border: solid black 1px;
border-collapse: collapse;
}
td
{
padding: 10px;
}
</style>
</head>
<body>
Examination Paper Analysis
<table>
<tbody>
<tr>
<td>Name : </td>
<td> <input type="text" id="name" required></td>
</tr>
<tr>
<td>Email : </td>
<td> <input type="email" id="email" required></td>
</tr>
<tr>
<td>Pin code : </td>
<td> <input type="number" id="pin" required></td>
</tr>
<tr>
<td></td>
<td><button onclick="submit()">Submit</button></td>
</tr>
</tbody>
</table>
</body>
<script>
function submit()
{
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var pin = Number(document.getElementById("pin").value);
if(name.length==0 || email.length==0 || pin.length==0)
{
alert("Please enter value in all fields.")
}
else
{
var pinpattern =/^[4]{1}[0-9]{5}$/;
if( pinpattern.test(pin))
{
alert("Perfect Pin code");
}
Examination Paper Analysis
else
{
alert("Wrong Pin code.");
}
}
}
</script>
</html>
6.(a) Write HTML script that will display dropdown list containing options such as
Red, Green, Blue & Yellow. Write a JavaScript program such that when the
user selects any options. It will change the background colour of webpage.
Ans:
<html>
<body>
<label for="color">Choose a Background Color:</label>
<select name="color" id="color" class="color" onchange="changeColor()">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
</select>
<script type="text/javascript">
function changeColor() {
var color = document.getElementById("color").value;
switch(color){
case "green":
document.body.style.backgroundColor = "green";
break;
case "red":
document.body.style.backgroundColor = "red";
break;
case "blue":
document.body.style.backgroundColor = "blue";
break;
case "yellow":
document.body.style.backgroundColor = "yellow";
break;
default:
Examination Paper Analysis
document.body.style.backgroundColor = "white";
break;
}
}
</script>
</body>
</html>
Summe Unit 3 1.(d) Explain following form events : 2
r-2022 Form and (i) onmouseup
Event (ii) onblur
Handling Ans: 2
The onmouseup event occurs when a mouse button is released over an element.
4
Example:
<p id="myP" onmousedown="mouseDown()" onmouseup="mouseUp()">
The mouseDown() function sets the color of this text to red. 4
The mouseUp() function sets the color of this text to blue.
</p>

The onblur event occurs when an HTML element loses focus.


Example:
<input type="text" id="fname" onblur="myFunction()">
<script>
function myFunction() {
let x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}

1.(e) Write a javascript program to changing the contents of a window.


Ans:
In following example, we are creating only one object of window and each time same window
remain open and content of window changes.
<html>
<body>
<script>
function openWin1(ad)
{
myWindow = window.open(ad, "myWindow", "width=500,height=500");
}
Examination Paper Analysis
</script>
<button value="Google"
onclick="openWin1('https://www.google.com')">Google</button>
<button value="Vidyalankar"
onclick="openWin1('http://vpt.edu.in')">Vidyalanakr</button>
</body>
<html>

2.(c) Write a javascript program to demonstrate java intrinsic function.


Ans:
An intrinsic function is often used to replace the Submit button and the Reset button with your
own graphical images, which are displayed on a form in place of these buttons.

Example:
<html>
<head>
<title>Using Intrinsic JavaScript Functions</title>
</head>
<body>
<FORM name="contact" action="#" method="post">
<P>
First Name: <INPUT type="text" name="Fname"/> <BR>
Last Name: <INPUT type="text" name="Lname"/><BR>
Email: <INPUT type="text" name="Email"/><BR>
<img src="submit.jpg"
onclick="javascript:document.forms.contact.submit()"/>
<img src="reset.jpg"
onclick="javascript:document.forms.contact.reset()"/>
</P>
</FORM>
</body>
</html>

3.(c) Write a javascript program to calculate add, sub, multiplication and division
of two number (input from user). Form should contain two text boxes to input
numbers of four buttons for addition, subtraction, multiplication and division.
Ans:
<html>
Examination Paper Analysis
<head>
<script>
function multiplyBy()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 * num2;
}

function divideBy()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 / num2;
}
function add()
{
num1 = parseInt(document.getElementById("firstNumber").value);
num2 = parseInt(document.getElementById("secondNumber").value);
document.getElementById("result").innerHTML = num1 + num2;
}
function subtract()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 - num2;
}
</script>
</head>
<body>
<form>
1st Number : <input type="text" id="firstNumber"><br>
2nd Number: <input type="text" id="secondNumber"><br><br>
<input type="button" onClick="multiplyBy()" Value="Multiply">
<input type="button" onClick="divideBy()" Value="Divide">
<input type="button" onClick="add()" Value="Addition">
<input type="button" onClick="subtract()" Value="Subtraction">
</form>
Examination Paper Analysis
<p>The Result is : <br>
<p id = "result"></p>
</p>
</body>
</html>
Summe Unit 4 Q3 d. Explain how to create and read Persistent Cookies in JavaScript with example. 4
r-2023 Ans:

A cookie is an amount of information that persists between a server-side and a


client-side.

A persistent cookie is a cookie that is assigned an expiration date.

Example:

<html>
<head>
<script>
function writeCookie()
{
var d=new Date();
d.setTime(d.getTime()+(1000*60*60*24));
with(document.myform)
{
document.cookie="Name=" + person.value + ";expires=" +d.toGMTString();
}
}
function readCookie()
{
if(document.cookie=="")
document.write("cookies not found");
else
document.write(document.cookie);
}
</script>
</head>
<body>
Examination Paper Analysis
<form name="myform" action="">
Enter your name:
<input type="text" name="person"><br>
<input type="Reset" value="Set C" type="button" onclick="writeCookie()">
<input type="Reset" value="Get C" type="button" onclick="readCookie()">
</form>
</body>
</html>
Winter- Unit 4 Q1 g. Describe browser location object. 2
2022 Ans: 6
i) The location object contains information about the current URL. 6
ii) The location object is a property of the window object.
iii) The location object is accessed with: window.location or just location.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>The Window Location Object</h1>
<p id="demo"></p>
<script>
let origin = window.location.origin;
document.getElementById("demo").innerHTML = origin;
</script>
</body>
</html>
Q5 a. Write HTML script that will display following structure
Examination Paper Analysis
Write the JavaScript code for below operations : (1) Name, Email & Pin Code should not be blank.
(2) Pin Code must contain 6 digits & it should not be accept any characters.
Ans:
<html>
<head>
<style>
table,tr,td
{
border: solid black 1px;
border-collapse: collapse;
}
td
{
padding: 10px;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td>Name : </td>
<td> <input type="text" id="name" required></td>
</tr>
<tr>
<td>Email : </td>
<td> <input type="email" id="email" required></td>
</tr>
<tr>
<td>Pin code : </td>
<td> <input type="number" id="pin" required></td>
</tr>
<tr>
<td></td>
Examination Paper Analysis

<td><button onclick="submit()">Submit</button></td>
</tr>
</tbody>
</table>
</body>
<script>
function submit()
{
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var pin = Number(document.getElementById("pin").value);
if(name.length==0 || email.length==0 || pin.length==0)
{
alert("Please enter value in all fields.")
}
else
{
var pinpattern =/^[4]{1}[0-9]{5}$/;
if( pinpattern.test(pin))
{
alert("Perfect Pin code");
}
else
{
alert("Wrong Pin code.");
}
}
}
</script>
</html>
Q5 b. Write a webpage that displays a form that contains an input for username & password.
User is prompted to entre the input & password & password becomes the value of the cookie.
Write a JavaScript function for storing the cookie. It gets executed when the password changes.
Ans:
Examination Paper Analysis

<html>
<head>
<script>
function storeCookie()
{
var pwd = document.getElementById('pwd').value
document.cookie = "Password=" + pwd + ";"
alert("Cookie Stored\n"+document.cookie);
}
</script>
</head>
<body>
<form name="myForm">
Enter Username <input type="text" id="uname"/><br/>
Enter Password <input type="password" id="pwd"/><br/>
<input type="button" value="Submit" onclick="storeCookie()"/>
<p id="panel"></p>
</form>
</body>
</html>
Summer Unit 4 Q1 b. Differentiate between session cookies and persistent cookies. 2
-2022 Ans: 2
Session Cookies persistent cookies 2
It resides in memory for the length of the A persistent cookie is a cookie that is assigned 4
browser session. an expiration date. 4
6
Also known as an in-memory cookie Also known as transient cookie.

Session cookie is automatically deleted when It is written to the computer’s hard disk and
the user exits the browser application. remains there until the expiration date has been
reached; then it’s deleted.
Examination Paper Analysis

Q1 e. Write a JavaScript program to changing the contents of a window.


Ans:
In following example, we are creating only one object of window and each time same window remain
open and content of window changes.
<html>
<body>
<script>
function openWin1(ad)
{
myWindow = window.open(ad, "myWindow", "width=500,height=500");
}
</script>
<button value="Google" onclick="openWin1('https://www.google.com')">Google</button>
<button value="Vidyalankar" onclick="openWin1('http://vpt.edu.in')">Vidyalanakr</button>
</body>
<html>

Q1 g. Write a JavaScript syntax to accessing elements of another child window.


Ans:
From the top level window that contains the iFrame you start by getting a reference to the iFrame by using
plain old getElementById to select the iFrame by Id. Alternately you can also access the frame via
window.frames[0] (or appropriate numeric index). Once the iFrame is selected you can use the
contentDocument property to access the child frame content. From there you can access document
methods as you normally would – in this case by using getElementById() and then assigning some HTML
to the display <div> tag in the child frame.
Example: window.frames[0].showMessage("Hello from Main Page in iFrame");

Q2 d. Design a webpage that displays a form that contains an input for user name and password. User is
prompted to enter the input user name and password and password become value of the cookies. Write the
JavaScript function for storing the cookies.
Ans:
<html>
<head>
Examination Paper Analysis

<script>
function storeCookie()
{
var pwd = document.getElementById('pwd').value
document.cookie = "Password=" + pwd + ";"
alert("Cookie Stored\n"+document.cookie);
}
</script>
</head>
<body>
<form name="myForm">
Enter Username <input type="text" id="uname"/><br/>
Enter Password <input type="password" id="pwd"/><br/>
<input type="button" value="Submit" onclick="storeCookie()"/>
<p id="panel"></p>
</form>
</body>
</html>

Q3 a. Write a JavaScript program to create read, update and delete cookies.


Ans:
<html>
<head>
<script>
function writeCookie()
{
var d=new Date();
d.setTime(d.getTime()+(1000*60*60*24));
with(document.myform)
{
document.cookie="Name=" + person.value + ";expires=" +d.toGMTString();
}
}
Examination Paper Analysis

function readCookie()
{
if(document.cookie=="")
document.write("cookies not found");
else
document.write(document.cookie);
}
</script>
</head>
<body>
<form name="myform" action="">
Enter your name:
<input type="text" name="person"><br>
<input type="Reset" value="Set" type="button" onclick="writeCookie()">
<input type="Reset" value="Get" type="button" onclick="readCookie()">
</form>
</body>
</html>

Q6 a. Write a JavaScript to open a new window and the new window is having two frames. One frame
containing button as “click here !”, and after clicking this button an image should open in the second
frame of that child window.
Ans:
Code:
f.html
<html>
<head>
<title>Create a Frame</title>
</head>
<frameset rows="60%,40%">
<frame src="b.html" name="a" />
<frame src="im.html" name="b" />
</frameset>
Examination Paper Analysis

</frameset>
</html>

b.html
<html>
<head>
<title>Web Page 1</title>
</head>
<body>
<form action="" method="post">
<p><a href="j.png" target="b">
<input name="WebPage1" value="Click here!" type="button">
</a></p>
</body>
</html>

im.html
<html>
<head>
<title>Web Page 1</title>
</head>
<body>
<img src="i.png">
</body>
</html>
Summer Unit 5 Q4 d. Explain text and image rollover with suitable example. 2
-2023 Ans: 6
6
Text rollover:
We can also create a rollover and rollback for text using the onmouseover and onmouseout.

Ans:
Examination Paper Analysis

<html>
<head>
<title>
text rollovers</title>
</head>
<body>
<table border="1" width="100%">
<tbody>
<tr valign="top">
<td width="50%">
<a><img height="500" src="blue.png" width="900" name="clr"></a></td>
<td><a onmouseover="document.clr.src='blue.png' ">
<b><u> Blue Color</u></b></a> 55

<br>
<a onmouseover="document.clr.src='red.png' ">
<b><u> Red Color</u></b></a>
<br>
<a onmouseover="document.clr.src='green.png' ">
<b><u> Green Color</u></b></a>
</td>
</tr>
</tbody>
</table>
</body>
</html>

Image Rollover:
<html>
<head>
<title>JavaScript Image Rollovers</title>
</head>
<body>
Examination Paper Analysis

<img src="blue.png" name="image1" onmouseover="src='car.jpg' " onmouseout="src='blue.png' ">


</img>
</body>
</html>

Q5 c. Write HTML code to design a form that displays textboxes for accepting UserID and Aadhar No.
and a SUBMIT button. UserlD should contain 10 alphanumeric characters and must start with Capital
Letter. Aadhar No. should contain 12 digits in the format nnnn nnnn nnnn. Write JavaScript code to
validate the UserID and Aadhar No. when the user clicks on SUBMIT button.
Ans:

<html>
<body>
<script>
function submitdata()
{
Var userID=document.getElementById(‘uid’).value;
Var aadharno=document.getElementById(‘uaadhatNo’).value;
Var userIDExp=/^[A-Z][A-Z a-z 0-9] {9} $/;
Var aadharIDExp=/^\d{4} \d{4} \d{4} $/;

If(!userIDExp.test(userID))

{
Alert(“Invalid userID, it should contain 10 alphanumeric character);
}
Else if(!aadharNoExp.test(aadharNo);
{
Alert(“Invalid aadharNo, It should be in the nnnn nnnn nnnn format);
}
Else
{
Alert(“valid user”);
Examination Paper Analysis

}
}
</script>
<form>
<inpt id=”aadhar no” type=”text” placeholder=”Enter your adhar no” required><br><br>
<button onclick=”Submitdata()”>
Submit</button>
</form>
</body>
</html>

Q6 b. Write a script for creating following frame structure : Frame 1 contains three buttons SPORT,
MUSIC and DANCE that will perform following action : When user clicks SPORT button, sport.html
webpage will appear in Frame 2. When user clicks MUSIC button, music.html webpage will appear in
Frame 3. When user clicks DANCE button, dance.html webpage will appear in Frame 4.

Ans:

<html>
<head>
<title> main frame</title>
Examination Paper Analysis

</head>
<frameset rows=”20%, 20%,60%”>
<frameset cols=”*,*,*”>
<frame src=”frame5.html>
<frame src=”frame1.html>
<frame src=”frame5.html>
</frameset>
<frame src=”finalf.html”>
<frameset cols=”*,*,*”>
<frame src=”frame2.html>
<frame src=”frame3.html>
<frame src=”frame4.html>

</frameset>
</frameset>
</html>

Frame1.html

<html>
<body>
<center><b>frame1
</body>
</html>

Frame2.html

<html>
<head>
<body>
Welcome to Sport Page
</body>
</html>
Examination Paper Analysis

Frame3.html

<html>
<head>
<body>
Welcome to Music Page
</body>
</html>

Frame4.html

<html>
<head>
<body>
Welcome to Dance Page
</body>
</html>

Frame5.html

<html>
<head>
<body>
</body>
</html>

Frame6.html

<html>
<head>
Examination Paper Analysis

<body>
<button onclick=”Frame2.html”>Sport</button>
</body>
</html>

Frame7.html

<html>
<head>
<body>
<button onclick=”Frame3.html”>Sport</button>
</body>
</html>

Frame8.html

<html>
<head>
<body>
<button onclick=”Frame4.html”>Sport</button>
</body>
</html>

Winter- Unit 5 Q3 d. Write a JavaScript function that will open new window when the user will clicks on the button. 4
2022 Ans: 4
<html> 4
<body> 4
<button onclick="openWin()">Open "New Window"</button> 6
<script>
var myWindow;
function openWin()
{
Examination Paper Analysis

myWindow = window.open("", "myWindow", "width=400,height=400");


myWindow.document.write("<p>Hello Everyone.Welcome to new window.</p>");
}
</script>
</body>
</html>
Q4 a. Describe text Rollover with the help of example.
Ans:
Rollover means a webpage changes when the user moves his or her mouse over an object on the page. It is
often used in advertising. There are two ways to create rollover, using plain HTML or using a mixture of
JavaScript and HTML. We will demonstrate the creation of rollovers using both methods.
The keyword that is used to create rollover is the <onmousover> event.
For example, we want to create a rollover text that appears in a text area. The text “What is rollover?”
appears when the user place his or her mouse over the text area and the rollover text changes to “Rollover
means a webpage changes when the user moves his or her mouse over an object on the page” when the
user moves his or her mouse away from the text area.
The HTML script is shown in the following example:
Example:
<html>
<head></head>
<Body>
<textarea rows="2" cols="50" name="rollovertext" onmouseover="this.value='What is rollover?'"
onmouseout="this.value='Rollover means a webpage changes when the user moves his or her mouse over
an object on the page'"></textarea>
</body>
</html>
Q4 c. Describe Quantifiers with the help of example.
Ans:
The frequency or position of bracketed character sequences and single characters can be denoted by a
special character. Each special character has a specific connotation.
The +, *, ?, and $ flags all follow a character sequence.

Sr.No Expression & Description


Examination Paper Analysis

1 p+
It matches any string containing one or more p's.
2 p*
It matches any string containing zero or more p's.
3 p?
It matches any string containing at most one p.(zero or one occurrences)
4 p{N}
It matches any string containing a sequence of N p's
5 p{2,3}
It matches any string containing a sequence of two or three p's.
6 p{2, }
It matches any string containing a sequence of at least two p's.
7 p$
It matches any string with p at the end of it.

Example:
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
var str = "100, 1000 or 10000?";
var patt1 = /\d{3,4}/g;
var result = str.match(patt1);
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>

Q4 d. Describe frameworks of JavaScript & its application.


Examination Paper Analysis

Ans:
Frameworks of JavaScript:
1. ReactJs
React is based on a reusable component. Simply put, these are code blocks that can be classified as either
classes or functions. Each component represents a specific part of a page, such as a logo, a button, or an
input box. The parameters they use are called props, which stands for properties.
Applications:
React is a JavaScript library developed by Facebook which, among other things, was used to build
Instagram.com.
2. Angular
Google operates this framework and is designed to use it to develop a Single Page Application (SPA).
This development framework is known primarily because it gives developers the best conditions to
combine JavaScript with HTML and CSS. Google operates this framework and is designed to use it to
develop a Single Page Application (SPA). This development framework is known primarily because it
gives developers the best conditions to combine JavaScript with HTML and CSS.
Applications:
Microsoft Office ,Gmail, Forbes, PayPal, Grasshopper, Samsung, Delta
3. Vue.js
Vue is an open-source JavaScript framework for creating a creative UI. The integration with Vue in
projects using other JavaScript libraries is simplified because it is designed to be adaptable.
Application:
VueJS is primarily used to build web interfaces and one-page applications. It can also be applied to both
desktop and mobile app development.
4. jQuery
It is a cross-platform JavaScript library designed to simplify HTML client-side scripting. You can use the
jQuery API to handle, animate, and manipulate an event in an HTML document, also known as DOM.
Also, jQuery is used with Angular and React App building tools.
Applications:
JQuery can be used to develop Ajax based applications. 2. It can be used to make code simple, concise
and reusable. 3. It simplifies the process of traversal of HTML DOM tree. 4. It can also handle events,
perform animation and add ajax support in web applications.
5. Node.js
Node.js is an open-source, server-side platform built on the Google Chrome JavaScript Engine. Node.js is
Examination Paper Analysis

an asynchronous, single-threaded, non-blocking I/O model that makes it lightweight and efficient.
Applications:
Paypal, LinkedIn, Yahoo, Mozilla, Netflix, Uber, Groupon, GoDaddy, eBay
Q5 c. Write a JavaScript for creating following frame structure :

Chapter 1 & Chapter 2 are linked to the webpage Ch1 HTML & Ch2.html respectively. When user click
on these links corresponding data appears in FRAME3.
Ans:
Step 1) create file frame1.html
<html>
<body>
<h1 align="center">FRAME1</h1>
</body>
</html>
Step 2) create frame2.html
<html>
<head>
<title>FRAME 2</title>
</head>
<body><H1>Operating System</H1>
<a href="Ch1.html" target="c"><UL>Chapter 1</UL></a>
<br>
<a href=" Ch2.html" target="c"><UL> Chapter 2</UL></a>
</body>
</html>
Step 3) create frame3.html
<html>
Examination Paper Analysis

<body>
<h1>FRAME3</h1>
</body>
</html>
Step4) create frame_target.html
<html>
<head>
<title>Create a Frame</title>
</head>
<frameset rows="30%,*" border="1">
<frame src="frame1.html" name="a" />
<frameset cols="50%,*" border="1">
<frame src="frame2.html" name="b" />
<frame src="frame3.html" name="c" />
</frameset>
</frameset>
</html>
Summer Unit 5 Q3 d. State what is regular expression. Explain its meaning with the help of a suitable example. 4
-2022 Ans: 4
4
A regular expression is an object that describes a pattern of characters. 6

The JavaScript RegExp class represents regular expressions, and both String and RegExp define methods
that use regular expressions to perform powerful pattern-matching and search-and-replace functions on
text.

A Regular Expression is a sequence of characters that constructs a search pattern. When you search for
data in a text, you can use this search pattern to describe what you are looking for.

Syntax:
A regular expression is defined with the RegExp () constructor as:
var pattern = new RegExp(pattern, attributes);
Examination Paper Analysis

or simply
var pattern = /[pattern]/attributes;

Here,

● Pattern – A string that specifies the pattern of the regular expression or another regular expression.
● Attributes – An optional string containing attributes that specify global, case-insensitive, and
multi-line matches.

Example:
<html>
<body>
<script>
//validating mobile number
function validatePhone(num) {

// regex pattern for phone number


var re =/^\d{10}$/;

// check if the phone number is valid


var result = num.match(re);
if (result) {
document.write('The number is valid.');
}
}
// take input
var number = prompt('Enter a 10 digit mob number ');
validatePhone(number);
</script>
</body>
</html>

Q4 c. Write a JavaScript program to validate email ID of the user using regular expression.
Examination Paper Analysis

Ans:
<html>
<head>
<title>JavaScript Regular expression to valid an email address</title>
</head>
<body>
<script>
function valid_email(str)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(mailformat.test(str))
{
alert("Valid email address!");
}
else
{
alert("You have entered an invalid email address!");
}
}
valid_email('[email protected]');
</script>
</body>
</html>

Q4 d. Write a JavaScript program to design HTML page with books information in tabular format, use
rollovers to display the discount information.
Ans:
<html>
<head>
<title>
table rollovers</title>
<script>
function open_new_window(clrname)
Examination Paper Analysis

{
if(clrname==1)
{
document.clr.src="c.jpg";
mwin=window.open('','myadwin','height=50,width=50,left=500,top=200');
mwin.document.write("Discount is 50%");
}
if(clrname==2)
{
document.clr.src="java.jpg";
mwin=window.open('','myadwin','height=50,width=50,left=500,top=200');
mwin.document.write("Discount is 40%");
}

if(clrname==3)
{
document.clr.src="p.jpg";
mwin=window.open('','myadwin','height=100,width=150,left=500,top=200');
mwin.document.write("Discount is 20%");
}
}
</script>
</head>
<body>
<table border="1" width="100%">
<tbody>
<tr>
<td width="50%">
<a><img height="500" src="c.jpg" width="400" name="clr"></td>
<td><H2>
<a onmouseover="open_new_window(1)" onmouseout="mwin.close()">
<b><u>Programming in C</u></b></a>
<br><br>
Examination Paper Analysis

<a onmouseover="open_new_window(2)" onmouseout="mwin.close()">


<b><u>Java</u></b></a>
<br><br>
<a onmouseover="open_new_window(3)" onmouseout="mwin.close()">
<b><u>Python</u></b></a>
</H2>
</td>
</tr>
</tbody>
</table>
</body>
</html>

Q6 b. Write a JavaScript to create option list containing list of images and then display images in new
window as per selection.
Ans:
<html>
<body>
<label for="contries">Choose a Country:</label>
<select name="contries" id="contries" class="select" onchange="changecontry()">
<option value="india">India</option>
<option value="japan">Japan</option>
<option value="usa">USA</option>
</select>

<script>
changecontry= () => {
var contries = document.getElementById("contries").value;
switch(contries)
{
case "india":
var myWindow=window.open("i.png","MsgWindow", "width=200,height=100");
break;
Examination Paper Analysis

case "japan":
var myWindow=window.open("j.png","MsgWindow", "width=200,height=100");
break;
case "usa":
var myWindow=window.open("u.png","MsgWindow", "width=200,height=100");
break;
default:
/*document.getElementById("city-name").innerHTML = "Nill";
document.getElementById("city-description").innerHTML = "Nill";
document.getElementById("city-image").src = "";*/
break;
}
}</script>
</body>
</html>

Summer Unit 6 Q4 b. List Ways of protecting your web page and describe any one of them. 4
-2023 Ans: 4
There is nothing secret about your web page. Anyone with a little computer knowledge can use a few 4
mouse clicks to display your HTML code, including your JavaScript, on the screen. 6

Following are the ways to protect web pages:


1) Hiding Your Code by disabling Right Mouse Click:
The following example shows you how to disable the visitor's right mouse button while the browser
displays your web page. All the action occurs in the JavaScript that is defined in the <head> tag of the
web page.

<html>
<head>
<script>
window.onload = function()
{
Examination Paper Analysis

document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>

The preventDefault() method cancels the event if it is cancelable, meaning that the default action that
belongs to the event will not occur.

For example, this can be useful when:

● Clicking on a "Submit" button, prevent it from submitting a form


● Clicking on a link, prevent the link from following the URL

2) Hiding JavaScript
You can hide your JavaScript from a visitor by storing it in an external file on your web server. The
external file should have the .js file extension. The browser then calls the external file whenever the
browser encounters a JavaScript element in the web page. If you look at the source code for the web page,
you'll see reference to the external .js file, but you won't see the source code for the JavaScript.

webpage.html
<html>
<head>
<script src="mycode.js" languages="javascript" type="text/javascript">
</script>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
Examination Paper Analysis

</html>
mycode.js
window.onload=function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
}

3) Concealing Your E-mail Address


● To conceal an e-mail address, you need to create strings that contain part of the
e-mail address and then build a JavaScript that assembles those strings into the e-mail address,
which is then written to the web page.
● The following example illustrates one of many ways to conceal an e-mail address.
● It also shows you how to write the subject line of the e-mail. We begin by creating four strings:
• The first string contains the addressee and the domain along with symbols
&, *, and _ (underscore) to confuse the bot.
• The second and third strings contain portions of the mailto: attribute name.
Remember that the bot is likely looking for mailto:
• The fourth string contains the subject line. As you'll recall from your HTML
training, you can generate the TO, CC, BCC, subject, and body of an e-mail from
within a web page.
● You then use these four strings to build the e-mail address. This process starts by using the
replace() method of the string object to replace the & with the @ sign and the * with a period (.).
The underscores are replaced with nothing, which is the same as simply removing the underscores
from the string.

<html>
<head>
<title>Conceal Email Address</title>
<script>
Examination Paper Analysis

function CreateEmailAddress()
{
var x = 'abcxyz*c_o_m'
var y = 'mai'
var z = 'lto'
var s = '?subject=Customer Inquiry'
x = x.replace('&','@')
x = x.replace('*','.')
x = x.replace('_','')
x = x.replace('_','')
var b = y + z +':'+ x + s
window.location=b;
}

</script>
</head>
<body>
<input type="button" value="send" onclick="CreateEmailAddress()">
</body>
</html>

Q4 c. Explain how to create and display Rotating Banner in JavaScript with example.
Ans:
Following steps must be follow for creating banner in javascript:

1. Load banner advertisements into an array.


2. Determine whether the browser supports the image object.
3. Display a banner advertisement.
4. Pause before displaying the next banner advertisement.

Example:
Examination Paper Analysis

<html >
<head>
<title>Banner Ads</title>
<script>
Banners = new Array('1.jpg','2.jpg','3.jpg');
CurrentBanner = 0;
function DisplayBanners()
{
if (document.images);
{
CurrentBanner++;
if (CurrentBanner == Banners.length)
{
CurrentBanner = 0;
}
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
}
}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<img src="1.jpg" width="400"
height="75" name="RotateBanner" />
</center>
</body>
</html>

Q4 e. What is Status bar and how to display moving message on the status line of a window using
JavaScript.
Ans:
To set the text in the status bar at the bottom of the browser window. The HTML standards now requires
Examination Paper Analysis

setting window.status to have no effect on the text displayed in the status bar.
<script>
Var scrollpos=0
Var maxscroll=100;
Var blank=” “
Function scrollText(text,milliseconds)
{
Window.setInterval(“displayText(“+text+”);milliseconds)
}
Function displayText(text)
{
Window.defaultStatus=blanks+text++scrollpos
Blanks+=” “
If(scrollpos>maxscroll)
{
Scrollpos=0
Blanks=” “
}
</script>

Q6 c. Write a JavaScript to create a pull - down menu with four options [AICTE, DTE, MSBTE,
GO0GLE]. Once the user will select one of the options then user will be redirected to that site.
Ans:

<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function getPage(choice)
{
page=choice.options[choice.selectedIndex].value;
if(page != "")
{
Examination Paper Analysis

window.location=page;
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Website:
<select name="MenuChoice" onchange="getPage(this)">
<option
value="https://www.google.com">Google</option>
<option
value="https://www.msbte.org.in">MSBTE</option>
<option
value="https://www.aicte-india.org/">AICTE</option>
<option
value="https://poly23.dtemaharashtra.gov.in/diploma23/">DTE</option>

</form>
</body>
</html>
Winter- Unit 6 Q4 b. Write a JavaScript program that will create pull-down menu with three options. Once the user will 4
2022 select the one of the options then user will redirected to that website. 4
Ans: 6
<html> 6
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function getPage(choice)
{
page=choice.options[choice.selectedIndex].value;
if(page != "")
{
Examination Paper Analysis

window.location=page;
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Website:
<select name="MenuChoice" onchange="getPage(this)">
<option value="select any option">Select</option>
<option value="https://www.codecademy.com/catalog/language/javascript/">
CodeAcademy </option>
<option value="https://www.msbte.org.in">MSBTE</option>
<option value="https://www.javatpoint.com/javascript-tutorial">JavaTpoint</option>
</form>
</body>
</html>
Q4 e. Describe how to link banner advertisement to URL with example.
Ans:
The banner advertisement is the hallmark of every commercial web page. It is typically positioned near
the top of the web page, and its purpose is to get the visitor's attention by doing all sorts of clever things.
To get additional information, the visitor is expected to click the banner so that a new web page opens.
You can link a banner advertisement to a web page by inserting a hyperlink into your web page that calls
a JavaScript function rather than the URL of a web page. The JavaScript then determines the URL that is
associated with the current banner and loads the web page that is associated with the URL.
Example:
<html>
<head>
<title>Link Banner Ads</title>
<script language="Javascript" type="text/javascript">
Banners = new Array('1.jpg','2.jpg','3.jpg')
BannerLink = new Array(
'google.com/','vpt.edu.in/', 'msbte.org.in/');
Examination Paper Analysis

CurrentBanner = 0;
NumOfBanners = Banners.length;
function LinkBanner()
{
document.location.href =
"http://www." + BannerLink[CurrentBanner];
}
function DisplayBanners() {
if (document.images) {
CurrentBanner++
if (CurrentBanner == NumOfBanners) {
CurrentBanner = 0
}
document.RotateBanner.src= Banners[CurrentBanner]
setTimeout("DisplayBanners()",1000)
}
}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<a href="javascript: LinkBanner()"><img src="1.jpg"
width="400" height="75" name="RotateBanner" /></a>
</center>
</body> </html>
Q6 b. Develop a JavaScript program to create Rotating Banner Ads.
Ans:
<html >
<head>
<title>Banner Ads</title>
<script>
Banners = new Array('1.jpg','2.jpg','3.jpg');
CurrentBanner = 0;
Examination Paper Analysis

function DisplayBanners()
{
if (document.images);
{
CurrentBanner++;
if (CurrentBanner == Banners.length)
{
CurrentBanner = 0;
}
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
}
}
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<img src="1.jpg" width="400"
height="75" name="RotateBanner" />
</center>
</body>
</html>
Q6 c. Write a JavaScript for the folding tree menu.
Ans:
<html>
<head>
<style>
ul, #myUL {
list-style-type: none;
}
.caret::before {
content: "\25B6";
color: black;
Examination Paper Analysis

display: inline-block;
margin-right: 6px;
}
.caret-down::before {
-ms-transform: rotate(90deg); /* IE 9 */
-webkit-transform: rotate(90deg); /* Safari */'
transform: rotate(90deg);
}
.nested {
display: none;
}
.active {
display: block;
}
</style>
</head>
<body>
<h2>Folding Tree Menu</h2>
<p>A tree menu represents a hierarchical view of information, where each item can have a number of
subitems.</p>
<p>Click on the arrow(s) to open or close the tree branches.</p>
<ul id="myUL">
<li><span class="caret">India</span>
<ul class="nested">
<li>Karnataka</li>
<li>Tamilnaadu</li>
<li><span class="caret">Maharashtra</span>
<ul class="nested">
<li>Mumbai</li>
<li>Pune</li>
<li><span class="caret">Navi Mumbai</span>
<ul class="nested">
<li>Nerul</li>
Examination Paper Analysis

<li>Vashi</li>
<li>Panvel</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<script>
var toggler = document.getElementsByClassName("caret");
var i;
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".nested").classList.toggle("active");
this.classList.toggle("caret-down");
});
}
</script>
</body>
</html>
Summer Unit 6 Q1 f. Explain frame works of JavaScript and its application. 2
-2022 Ans: 4
JavaScript frameworks are a type of tool that makes working with JavaScript easier and smoother. 6
1) Angular 6
2) React
3) Vue.js
4) Node.js
5) Backbone.js

Q3 b. Write a JavaScript program to link banner advertisements to different URLs.


Ans:
Examination Paper Analysis

<html>
<head>
<title>Link Banner Ads</title>
<script language="Javascript" type="text/javascript">

Banners = new Array('y.jpg','yy.jpg','yyy.jpg')


BannerLink = new Array(
'google.com/','vpt.edu.in/', 'msbte.org.in/');
CurrentBanner = 0;
NumOfBanners = Banners.length;
function LinkBanner(){
document.location.href =
"http://www." + BannerLink[CurrentBanner];
}
function DisplayBanners()
{
if (document.images)
{
CurrentBanner++;
if (CurrentBanner == NumOfBanners)
{
CurrentBanner = 0;
}
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
}
}
</script>
</head>
<body onload="DisplayBanners();" >
<center>
<a href="javascript: LinkBanner()">
<img src="1.jpg"
Examination Paper Analysis

width="400" height="200" name="RotateBanner" /></a>


</center>
</body>
</html>
Q4 e. List ways of protecting your webpage and describe any one of them.
Ans:
There is nothing secret about your web page. Anyone with a little computer knowledge can use a few
mouse clicks to display your HTML code, including your JavaScript, on the screen.

Following are the ways to protect web pages:


1) Hiding Your Code by disabling Right Mouse Click:
The following example shows you how to disable the visitor's right mouse button while the browser
displays your web page. All the action occurs in the JavaScript that is defined in the <head> tag of the
web page.

<html>
<head>
<script>
window.onload = function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>

The preventDefault() method cancels the event if it is cancelable, meaning that the default action that
Examination Paper Analysis

belongs to the event will not occur.

For example, this can be useful when:

● Clicking on a "Submit" button, prevent it from submitting a form


● Clicking on a link, prevent the link from following the URL

2) Hiding JavaScript
You can hide your JavaScript from a visitor by storing it in an external file on your web server. The
external file should have the .js file extension. The browser then calls the external file whenever the
browser encounters a JavaScript element in the web page. If you look at the source code for the web page,
you'll see reference to the external .js file, but you won't see the source code for the JavaScript.

webpage.html
<html>
<head>
<script src="mycode.js" languages="javascript" type="text/javascript">
</script>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
</html>
mycode.js
window.onload=function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
}
Examination Paper Analysis

3) Concealing Your E-mail Address


● To conceal an e-mail address, you need to create strings that contain part of the
e-mail address and then build a JavaScript that assembles those strings into the e-mail address,
which is then written to the web page.
● The following example illustrates one of many ways to conceal an e-mail address.
● It also shows you how to write the subject line of the e-mail. We begin by creating four strings:
• The first string contains the addressee and the domain along with symbols
&, *, and _ (underscore) to confuse the bot.
• The second and third strings contain portions of the mailto: attribute name.
Remember that the bot is likely looking for mailto:
• The fourth string contains the subject line. As you'll recall from your HTML
training, you can generate the TO, CC, BCC, subject, and body of an e-mail from
within a web page.
● You then use these four strings to build the e-mail address. This process starts by using the
replace() method of the string object to replace the & with the @ sign and the * with a period (.).
The underscores are replaced with nothing, which is the same as simply removing the underscores
from the string.

<html>
<head>
<title>Conceal Email Address</title>
<script>

function CreateEmailAddress()
{
var x = 'abcxyz*c_o_m'
var y = 'mai'
var z = 'lto'
var s = '?subject=Customer Inquiry'
x = x.replace('&','@')
x = x.replace('*','.')
x = x.replace('_','')
x = x.replace('_','')
Examination Paper Analysis

var b = y + z +':'+ x + s
window.location=b;
}

</script>
</head>
<body>
<input type="button" value="send" onclick="CreateEmailAddress()">
</body>
</html>

Q5 c. Write a JavaScript program to create a slide show with the group of six images, also simulate the
next and previous transition between slides in your JavaScript.

Ans:
<html>
<title>slideshow</title>
<body>
<h2 class="w3-center">Manual Slideshow</h2>
<div class="w3">
<img class="mySlides" src="1.jpg" style="width:50%">
<img class="mySlides" src="2.jpg" style="width:50%">
<img class="mySlides" src="3.jpg" style="width:50%">
<img class="mySlides" src="4.jpg" style="width:50%">
<img class="mySlides" src="5jpg" style="width:50%">
<img class="mySlides" src="6.jpg" style="width:50%">

<button class="aa" onclick="plusDivs(-1)">&#10094;Back</button>


<button class="bb" onclick="plusDivs(1)">&#10095;Forward</button>
</div>
Examination Paper Analysis

<script>
var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n)
{
showDivs(slideIndex += n);
}

function showDivs(n)
{
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length)
{
slideIndex = 1
}

if (n < 1)
{
slideIndex = x.length
}
for (i = 0; i < x.length; i++)
{
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</body>
</html>

You might also like