Quesion Bank UT-2 CSS(22519)
Quesion Bank UT-2 CSS(22519)
(DIPLOMA)
QUESTION BANK (Answers)
Unit Test-II
Program: - Computer Engineering Group Program Code: - CO
Course Title: -Client-Side Scripting Language Semester: - Fifth
Course Abbe &Code: -CSS (22519) Scheme: I
*Kindly Note: All the question are taken from previous year question papers
Summer-22, Winter-23, Summer-23 that includes Chapter No. 4,5 and 6
as per the instruction of Subject Teacher.
--------------------------------------------------------------------------------------------------
Summer – 2022
1. Unit IV: Cookies and Browser Data
2. Design a webpage with inputs for username and password, and write the
JavaScript function for storing these values in cookies. (Q2(d))
<html>
<body>
<form >
Enter Username: <input type="text" id="uname"/><br/>
Enter Password: <input type="password" id="pwd"/><br/>
<input type="button" value="Submit" onclick="storeCookie()"/>
</form>
<script>
function storeCookie() {
var pwd = document.getElementById('pwd').value;
CREATED BY PRACHI
document.cookie = "Password: " + pwd + ";";
alert("Cookie Stored" + document.cookie);
}
</script>
</body>
</html>
3. Write a JavaScript program to create, read, update, and delete cookies. (Q3(a))
<html >
<head>
<title>Cookie Example</title>
<script>
function setCookie(value) {
document.cookie = "username=" + value;
}
function getCookie() {
alert(document.cookie);
}
function updateCookie(value) {
setCookie(value);
alert("Cookie updated to: " + value);
}
function deleteCookie() {
document.cookie = "username=";
}
function example() {
setCookie('Trisha_Jadhav');
getCookie();
updateCookie('Prachi_Jadhav');
getCookie();
deleteCookie();
getCookie();
}
</script>
</head>
<body>
<h1>Cookie Example</h1>
CREATED BY PRACHI
<button onclick="example()">Run Example</button>
</body>
</html>
CREATED BY PRACHI
`);
newWindow.document.close();
}
</script>
</head>
<body>
<button onclick="openFrames()">Open New Window with Frames</button>
</body>
</html>
if (re.test(email)) {
alert('Email format seems valid');
}
else {
alert('Invalid Email ID');
}
}
</script>
</head>
<body onload="validateEmail()">
</body>
</html>
CREATED BY PRACHI
A regular expression can be a single character, or a more complicated
pattern
The JavaScript RegExp class represents regular expressions, and both
String and RegExp define methods.
It uses regular expressions to perform pattern-matching and search-and-
replace functions
Example:-
<html>
<head>
<script>
function Reg ()
{
var name="Prachi";
re=/[Pr]/;
if(re.test (name))
{
alert ('Found');
}
else
{
alert ('Not Found');
}
}
</script>
</head>
<body onload= "Reg ()" >
</body>
</html>
CREATED BY PRACHI
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
15%'">
<td> CSS </td>
<td> 230 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
10%'">
<td> AJP </td>
<td> 240 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
12%'">
<td> OSY </td>
<td> 260 </td>
</tr>
</table>
<p id="discount"></p>
</body>
</html>
3. Unit VI: Menus, Navigation, and Webpage Protection
1. Write a JavaScript program to link banner advertisements to different URLs.
(Q3(b))
<html>
<head>
<script>
var MyBanners = new Array('ajp.jpg','css.jpg');
var banner = 0;
var MyBannerLinks = new Array('https://bit.ly/ajp-book',
'https://bit.ly/css-guide');
function ShowLinks() {
document.location.href = MyBannerLinks[banner];
}
function ShowBanners() {
if (document.images) {
banner++;
if (banner == MyBanners.length) {
banner = 0;
CREATED BY PRACHI
}
document.ChangeBanner.src = MyBanners[banner];
setTimeout(ShowBanners, 3000);
}
}
</script>
</head>
<body onload="ShowBanners()">
<a href="javascript: ShowLinks()">
<img src="" width="500" height="500" name="ChangeBanner"/>
</a>
</body>
</html>
2. Write a javascript program to create a silde show with the group of six images,
also simulate the next and previous transition between slides in your javascript.
. (Q5(c))
<html>
<head>
<script>
img_array= new Array("pineapple.jpg","apple.jpg","strawberry.jpg",
"watermelon.jpg","orange.jpg","cherry.jpg")
img=0;
function DisplayImg(num)
{
img=img+num;
if(img>img_array.length-1)
{
img=0;
}
if(img<0)
{
img=img_array.length-1;
}
document.Slide.src=img_array[img];
}
</script>
<body>
<img src="book2.jfif" width="400" height="220" name="Slide"/>
<br></br>
<input type="button" value="Pervious" onclick="DisplayImg(-1)">
<input type="button" value="Next" onclick="DisplayImg(1)">
</body>
</html>
CREATED BY PRACHI
3. Write a JavaScript code to create an option list and display selected images in
a new window. (Q6(b))
<html>
<body>
<h2>Select an Image</h2>
<select id="image">
<option value="">--Choose an image--</option>
<option value="Red.jpg">Red Image</option>
<option value="Green.jpg">Green Image</option>
<option value="Blue.jpg">Blue Image</option>
</select>
4. List ways of protecting your webpage and describe any one of them. (Q4(e))
Hiding your source code
Disabling the right MouseButton
Hiding JavaScript
Concealing E-mail address.
• 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.
CREATED BY PRACHI
• First you must tell the browser that the content of the JavaScript is located in an
external file on the web server rather than built into the web page. You do this by
assigning the file name that contains the JavaScripts to the src attribute of the
<script> tag.
Example:-
Webpage1.html:
<html>
<head>
<script src="code.js" language="Javascript" type="text/javascript">
</script>
<body>
<h3> Right click on screen, Context Menu is disabled</h3>
</body>
</html>
Code.js:
window.onload=function()
{
document.addEventListener("contextmenu",function(e)
{ e.preventDefault();}, false);
}
CREATED BY PRACHI
Summer – 2023
Cookies
1. Explain how to create and read Persistent Cookies in JavaScript with an
example. (Q3(d))
Persistent cookies in JavaScript are those that remain stored on the user's
device after the browser session ends, allowing data to be retained even
after the browser is closed. Here's how you can create and read persistent
cookies in JavaScript.
1. Creating a cookie:
document.cookie = "user=Prachi; expires=Fri, 01 Jan 2025 00:00:00
UTC; path=/";
2. Reading a cookie:
function getCookie(name) {
var cookies = document.cookie.split("; ");
for (var cookie of cookies) {
const [key, value] = cookie.split("=");
if (key === name) return value;
}
return null;
}
document. write(getCookie("user")); // Outputs:Prachi
Browser
1. Write the use of charCodeAt() and fromCharCode() method with syntax
and example. (Q2(d))
1. charCodeAt()
The charCodeAt() method returns the Unicode value (character code) of
the character at a specified index in a string.
Syntax: string.charCodeAt(index);
Example:
var str = "Hello";
var charCode = str.charCodeAt(0); // Get the character code of 'H'
document. write(charCode); // Output: 7
CREATED BY PRACHI
2. String.fromCharCode()
The String.fromCharCode() method converts Unicode values to characters.
Syntax: String.fromCharCode(num1, ..., numN);
Example:
var char = String.fromCharCode(72); // Convert Unicode 72 to 'H'
document. write(char); // Output: H
2. Write HTML code to design a form with two buttons START and
STOP. Implement timer functionality to display a real-time digital clock
using JavaScript. (Q5(b))
<html>
<head>
<title>Digital Clock</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
margin-top: 100px;
font-size: 50px;
color: #333;
}
</style>
</head>
<body onload="setInterval(() => {
var date = new Date();
var time = (date.getHours() % 12 || 12) + ':' + ('0' + date.getMinutes()).slice(-2) + ':' +
('0' + date.getSeconds()).slice(-2) + ' ' + (date.getHours() >= 12 ? 'PM' : 'AM');
document.getElementById('clockDisplay').textContent = time;
}, 1000);">
<div id="clockDisplay"></div>
</body>
</html>
Regular Expressions
1. Explain test() and exec() method of the Regular Expression object with
an example. (Q4(a))
1. test() Method
The test() method checks whether a pattern exists in a given string.
It returns a Boolean value: true if the pattern is found, and otherwise false.
CREATED BY PRACHI
Syntax: regex.test(string);
Example:
var regex = /hello/;
var string = "hello world";
document.write(regex.test(string)); // Output: true
2. exec() Method
The exec() method searches for a match in a specified string and returns an
array containing the matched text if found. If there’s no match, it returns
null. This method is particularly useful when you need more information
about the match, such as capturing groups.
Syntax: regex.exec(string);
Example:
var regex = /hello/;
var string = "hello world";
document. write(regex.exec(string)); // Output: ["hello"]
In this example, exec() finds the match "hello" in the string and returns an
array with "hello" as the first element.
Frames
1. Write a script for creating a frame structure where clicking SPORT,
MUSIC, or DANCE buttons displays different web pages in separate
frames. (Q6(b))
Rollover
1. Explain text and image rollover with a suitable example. (Q4(d))
CREATED BY PRACHI
Text rollover:
• You can create as many rollovers as you want on your web page.
• A clever rollover technique used by some developers is to enable a visitor to see
additional information about an item described in text by placing the mouse
cursor on the text.
• You create a rollover for text by using the onmouseover attribute of the <A>
tag, which is the anchor tag. You assign the action to the onmouseover attribute
the same way as you do with an <IMG> tag.
<html>
<body>
<TABLE width="100%" border="0">
<TBODY>
<TR>
<TD>
<a>
<IMG height="250" src="CSS.jpg"
width="200" border="0" name="cover">
</a>
</TD>
<TD>
<IMG height="1" src="" width="10">
</TD>
<TD>
<A onmouseover="document.cover.src='CSS.jpg'">
<B><U>Client Side Scripting</U></B>
</A>
<BR>
<A onmouseover="document.cover.src='OSY.jpg'">
<B><U>Operating System</U></B>
</A>
<BR>
<A onmouseover="document.cover.src='STE.jpg'">
<B><U>Software Testing</U></B>
</A>
</TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
Image Rollover:
• The onmouseover event by using the onmouseover attribute of an HTML tag that
defines the object on the web page and then assign to the onmouseover attribute
CREATED BY PRACHI
the action you want performed when the event occurs.
• The <IMG> tag defines the image object. The value assigned to the src attribute
of the <IMG> tag identifies the image itself. Whenever the onmouseover event
occurs, we need to change the value of the src attribute to identify the new
image.
<html>
<head>
<title> RollOver</title>
</head>
<body>
<IMG src="CSS.jpg" height="150" width="100" alt="no image"
onmouseover="src='OSY.jpg'"/>
</body>
</html>
Status Bar
1. What is the Status bar, and how can you display a moving message on it
using JavaScript? (Q4(e))
<html>
<head>
<script>
msg="This is an example of scrolling message";
spacer="............ .............";
pos=0;
function ScrollMessage()
{
window.status=msg.substring(pos,msg.length)+spacer+msg.substring(0,pos);
pos++;
if(pos>msg.length)
pos=0;
window.setTimeout("ScrollMessage()",100);
}
ScrollMessage();
</script>
</head>
<body>
<p>Scrolling Message Example</p>
<p>Look at the status line at the bottom of the page</p>
</body>
</html>
CREATED BY PRACHI
Banner
1. Explain how to create and display a Rotating Banner in JavaScript with
an example. (Q4(c))
<html>
<head>
<script>
MyBanners=new Array('CSS.jpg','CSS1.jpg','OSY.jpg','STE.jpg')
banner=0
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<img src="banner1.jpg" width="400" height="800"
name="ChangeBanner"/>
</center>
</body>
</html>
Slide Show
Write a JavaScript program to create a slideshow with transitions between six
images. (Q5(c))Answer will given above
CREATED BY PRACHI
Menus
1. Write a JavaScript code to create a pull-down menu with options
[AICTE, DTE, MSBTE, GOOGLE] that redirects to the selected site.
(Q6(c))
<html>
<body>
Select a Website:
<select onchange="show(this)">
<option value="https://www.google.com">Google</option>
<option value="https://www.msbte.com">MSBTE</option>
<option value="https://www.yahoo.com">Yahoo</option>
</select>
<script>
function show(select)
{
window.location.href =select.value;
}
</script>
</body>
</html>
Webpage Protection
1. List ways of protecting your webpage and describe any one of them.
(Q4(b)Answer will given above
-------------------------------------------------------------------------------------------------------
CREATED BY PRACHI
Winter – 23
Cookies
1. State what a cookie is, explain its need, and state characteristics of
persistent cookies. (Q3(d))
A cookie is a small piece of data that is stored on a user's device
(such as a computer or smartphone) by a web browser when they visit
a website. Cookies are used to remember information about the user’s
interaction with the site, such as login credentials, preferences, or
tracking information.
Example : document.cookie = "username=Prachi; expires=Fri, 01 Dec
2024 12:00:00 UTC; path=/";
CREATED BY PRACHI
Browser
1. Describe the “navigator” object in JavaScript and describe the methods
used to display browser name and version. (Q2(b))
The navigator object in JavaScript is used to access the information of
the user's browser. ---- Using the 'navigator' object, you can get the
browser version and name and check whether the cookie is enabled in
the browser.
- The 'navigator' object is a property of the window object.
- The navigator object can be accessed using the read-only
window.navigator property.
Syntax: window.navigator.property;
OR
navigator.property;
CREATED BY PRACHI
}
</script>
</head>
</html>
Regular Expressions
1. Write a JavaScript that accepts a string and searches for the pattern
“MSBTE” using regular expressions. If the pattern is found, display
“Pattern is found,” otherwise display “Pattern is not found.” (Q4(a))
<html>
<body>
<script>
function find(input)
{
pattern=/MSBTE/
if(pattern.test(input))
{
document.write("Pattern is found")
}
else
{
document.write("Pattern is not found")
}
}
find("This is MSBTE example text")
</script>
</body>
</html>
CREATED BY PRACHI
^\(\d{3}\) - \(\d{8}\)$
3. List any three properties of regular expression objects and state their use.
(Q6(c)(ii))
Frames
1. Design a frameset layout for a webpage with the following frame
structure:
CREATED BY PRACHI
1. Write an HTML script that displays laptop brand names (Lenovo, HP,
DELL) with a default image. When the mouse moves over a brand
name, the respective laptop image should display in an adjacent box.
(Q4(c))
<html>
<head>
<script>
function changeImage(brand) {
var img = document.getElementById("laptopImage");
if (brand === "lenovo")
{
img.src = "lenovo.jpg"
}
else if (brand === "hp")
{
img.src = "hp.jpg"
}
else if (brand === "dell")
{
img.src = "dell.jpg"
}
}
</script>
</head>
<body>
<div style="display: flex; align-items: center;">
<ul style="list-style-type: disc; padding-right: 20px; margin: 0;">
<li onmouseover="changeImage('lenovo')">Lenovo</li>
<li onmouseover="changeImage('hp')">HP</li>
<li onmouseover="changeImage('dell')">DELL</li>
</ul>
<div>
<img id="laptopImage" src="" alt="Laptop Image" width="300"
height="200">
</div>
</div>
CREATED BY PRACHI
</body>
</html>
Status Bar
1. Write a JavaScript code to set a crawling message on the status bar:
“Welcome to the Mystic World of JavaScript,” starting when the page
loads. (Q6(b))
<html>
<head>
<script>
var msg="Welcome to the Mystic World of JavaScript... "
var interval
function scroll()
{
msg=msg.substring(1)+msg.charAt(0)
window.status=msg
}
window.onload=function()
{
interval=setInterval(scroll,150)
}
</script>
</head>
</html>
Banner
1. Explain how to create and display a rotating banner in
JavaScript. (Q4(c))
Steps:
1. Create several banner advertisements using a graphics tool such as
Photoshop. You'll want to make more than one advertisement so you
can rotate them on your web page using a JavaScript.
2. Create an <img> element in your web page with the height and width
necessary to display the banner advertisement.
3. Build a JavaScript that loads and displays the banner advertisements
in conjunction with the <img> element.
<html>
CREATED BY PRACHI
<head>
<script>
MyBanners=newArray('CSS.jpg','CSS1.jpg','OSY.jpg','STE.jpg')
banner=0
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<img src="banner1.jpg" width="400" height="800"
name="ChangeBanner"/>
</center>
</body>
</html>
Menus
1. Write a JavaScript that demonstrates the use of a floating menu along
with respective HTML code. (Q5(a))
<html>
<body>
<div style="position:fixed">
<select name="Fruits">
<option value="">Fruits Name</option>
<option value="0">Apple</option>
<option value="1">Banana</option>
<option value="2">Orange</option>
<option value="3">Mango</option>
</select>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
CREATED BY PRACHI
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
scroll down below
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
Again Scroll it
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
</body>
</html>
Webpage Protection
1.State the use of hiding JavaScript and describe the steps needed to
accomplish it. (Q4(e))
One method to prevent users from accessing the context menu,
includes options such as viewing source, which inspecting
elements and saving images, is by disabling right-clicking through
event listeners or CSS properties.
Webpage1.html:
<html>
<head>
<script src="code.js" language="Javascript"
type="text/javascript">
CREATED BY PRACHI
</script>
<body>
<h3> Right click on screen, Context Menu is disabled</h3>
</body>
</html>
Code.js:
window.onload=function()
{
document.addEventListener("contextmenu",function(e){
e.preventDefault();}, false);
}
CREATED BY PRACHI
CREATED BY PRACHI