0% found this document useful (0 votes)
21 views26 pages

s23 Solution

Uploaded by

bhatiaaveen95
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)
21 views26 pages

s23 Solution

Uploaded by

bhatiaaveen95
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/ 26

Examination Paper Analysis

Exam Unit No Question no as per MSBTE paper Marks


Year and Name
Summer Unit 1 1.(a) State the ways to display the output in JavaScript 2M
-2023 Basics of Ans:
JavaScript one
Programmin • Writing into an HTML element, using innerHTML. way for
g • Writing into the HTML output using document.write(). ½ mark
• Writing into an alert box, using window.alert().
• 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 true operat
|| or (x == 5 || y == 5) is false
or
! not !(x == y) is true
1 mark
for
each
operat
or
Examination Paper Analysis
1.(c) Write JavaScript to create object “student”with properties roll number ,name,branch,year,Delete 2M
branch property and display remaining properties of student object.
Proper
Ans: correct
<script>
logic
var student ={
roll_number:1001 progra
branch:”IF” m2
year:First marks
name:”XYZ”
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>
Examination Paper Analysis
2.(a) Explain getter and setter properties in JavaScript with suitable example. 4M
Ans:
Getter
JavaScript object accessors are used to access and update the objects. Getter and setter are used as object explan
accessors to get or set object properties.
ation 2
Getter method helps in accessing the object methods as object properties.
Setter method is used to set object properties. mark
Using getter and setter the javascript provides better data security and data quality. Setter
Example: explan
<!DOCTYPE html> ation 2
<html> marks
<body>
<script>
var car = {
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
2.(b) Explain Object creation in JavaScript using ‘new’ keyword with adding properties and methods with 4M
example
Ans: Object
A javascript object is an entity having state and behavior. creatio
JavaScript is an object based language.
n2
There are three ways to create object:
1) By Object Literal mark
2) By creating instance of object directly
adding
propert
3) By using an object constructor
y and
metho
Example: d2
<script> mark
var emp =new Object();
emp.id=101;
emp.name=””Yash Desai”
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 check if the 4M
current number is obb or even and display a message to the screen
Sample Output: Correc
“1 is odd” t logic
“2 is even”
progra
….............
….... m4
marks
Ans:

<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
Summer- Unit 2 1.(d) Write JavaScript that initializes an array called Colors with the names of 3 Colors and display array
2023 Array, elements. 2M
Function and Ans:
String <html lang="en"> Correct
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 Exampl
} e1M

Example:
<script>
function maxTwo(x,y)
{
if(x,y)
return x;
else
return y;
}
</script>
Examination Paper Analysis
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 the character charCo
in which you’re interested. If you don’t pass an argument, it defaults to index 0. deAt()
• The charCodeAt() method returns the Unicode number of the string:
var UnicodeNum = StringName.charCodeAt() 2M for
fromCh
Example: arCode
<script> ()
var x="Javatpoint";
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>
Examination Paper Analysis
3.(a) Differentiate between push() and join() method of array object with respect to use,syntax,return value and 4M
example.
Ans: Any 4
point
related
Push() Join()
to
This method adds zero or more elements to the end Returns the new string by concatenating all of the
of the array. elements in an array separated by a specified syntax,
character. return
Syntax: arr.push(element1, element2,----); Syntax: arr.join(separator); value
Separator is an optional parameter. By default it is and
comma exampl
Returns the new length of the array after appending Returns the string with all the array elements joined e
the new elements into the an array. by seperator
Example: Example”
<html> <html>
<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 correct
Middle Name: Narayana
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>
Examination Paper Analysis
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 array. ation 2
Syntax: arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added); marks
Parameter: Examp
•The first parameter defines the position where new elements should be added (spliced in). e2
•The second parameter defines how many elements should be removed. Marks
•The list_of_elemnts_to_be_added parameter define the new elements to be added(optional).

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

Summer- Unit 3 1.(f) Enlist any four mouse events with their use. 2
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
Examination Paper Analysis
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 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">
Examination Paper Analysis

Code:

<html>
<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>
Summer- Unit 4 Q3 d. Explain how to create and read Persistent Cookies in JavaScript with example. 4
2023 Ans:

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


Examination Paper Analysis
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>
<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>
Summer Unit 5 Q4 d. Explain text and image rollover with suitable example. 2
-2023 Ans: 6
6
Text rollover:
Examination Paper Analysis

We can also create a rollover and rollback for text using the onmouseover and onmouseout.

Ans:
<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>
Examination Paper Analysis

</head>
<body>
<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
{
Examination Paper Analysis

Alert(“valid user”);
}
}
</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>
Examination Paper Analysis

<title> main frame</title>


</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>
<body>
Examination Paper Analysis

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

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.
Examination Paper Analysis

<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
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>
Examination Paper Analysis

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

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
Examination Paper Analysis

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('_','')
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.
Examination Paper Analysis

3. Display a banner advertisement.


4. Pause before displaying the next banner advertisement.

Example:

<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>
Examination Paper Analysis

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
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)
{
Examination Paper Analysis

page=choice.options[choice.selectedIndex].value;
if(page != "")
{
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>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy