s23 Solution
s23 Solution
<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
</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>
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:
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
</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
<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.
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);
}
<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:
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>