100% found this document useful (1 vote)
114 views

CSS CT2 Combined

This document contains 10 questions related to JavaScript concepts and coding exercises. It covers topics like identifying the browser, session cookies, regular expressions, form validation, timing events, window properties, protecting webpages, storing passwords as cookies, creating frames, and developing a rotating banner ad. Code snippets are provided as examples for concepts like validating Aadhar numbers, disabling right click, and creating a multidimensional array for banner images and links.

Uploaded by

1918Narous Lopes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
114 views

CSS CT2 Combined

This document contains 10 questions related to JavaScript concepts and coding exercises. It covers topics like identifying the browser, session cookies, regular expressions, form validation, timing events, window properties, protecting webpages, storing passwords as cookies, creating frames, and developing a rotating banner ad. Code snippets are provided as examples for concepts like validating Aadhar numbers, disabling right click, and creating a multidimensional array for banner images and links.

Uploaded by

1918Narous Lopes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CSS Question Bank CT2

1. Write a JavaScript that identifies a running browser.


<html>
<body>
<script>
var browsername = window.navigator.userAgent;
document.write("You are using " + browsername);
</script>
</body>
</html>

Output: You are using Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Code/1.73.1 Chrome/102.0.5005.167 Electron/19.0.17 Safari/537.36

2. State and explain what is a session cookie?


• Cookies are small pieces of information which are stored on the Client’s machine and can
be accessed by the server and is used to identify a user over the computer network.
• There are two types of cookies: Session Cookies and Persistent Cookies.
• A session cookie is a simple text file that a website installs on its visitor's device for
temporary use. It helps track real-time changes in a user's activity while on a website,
such as adding items while shopping on e-commerce websites.
• Session cookies are automatically destroyed when the browser is closed. These cookies
can be made into persistent cookies by specifying the expires attribute of the cookie.

3. State what is a regular expression? Explain its meaning with the help of a suitable example.
• A regular expression is a sequence of characters that forms a specific search pattern.
• The search pattern can be used for operations like text search, text replacement and
validation operations.
• A regular expression can be a single character, a string or more complex pattern.
• A regular expression language is written between two “/” forward slashes.
• The language of regular expression consists of quantifiers, meta characters and character
classes.
• There are two ways a regular expression can be created. One is by using the literals and
other is by using the RegExp() constructor.
• Syntax for regexp is as follows:
o var pattern = /expression/
o var pattern = new RegExp(/expression/)

• Example:
<html>
<script>
let text = "Client Side Scripting";
let n = text.search(/Side/i);
//i is a modifier (modifies the search to be case-insensitive)
document.write(n);
</script>
</html>

Output: 7

4. Write a webpage that accepts Username and Aadhar card as input texts. When the user
enters Aadhar card number, the JavaScript validates card number and displays whether
card number is valid or not. (Assume valid Aadhar card format to be nnnn.nnnn.nnnn or
nnnn-nnnn-nnnn).
<html>
<body>
<script>
var username = prompt("Enter Username");
var aadhaar = prompt("Enter Aadhaar No.");
var pattern1 = /^\d{4,4}[-]\d{4,4}[-]\d{4,4}[-]\d{4,4}$/;
//format NNNN-NNNN-NNNN-NNNN
var pattern2 = /^\d{4,4}[.]\d{4,4}[.]\d{4,4}[.]\d{4,4}$/;
//format NNNN.NNNN.NNNN.NNNN
// \d matches any digit, {4,4} specifies minimum and max length,
// ^ specifies match the beginning, $ specifies match the end
var result = pattern1.test(aadhaar) || pattern2.test(aadhaar)
if (result) {
alert("Aadhar No. is Valid")
}
else
alert("Aadhar No. is Invalid")
</script>
</body>
</html>

5. Write the syntax of and explain use of following methods of JavaScript Timing Event.
a. setTimeout()
• The setTimeout() method is used call a function after a number of milliseconds.
• The function is called only once after the specified time.
• The clearTimeout() can be used to prevent the function from starting
• The syntax for setTimeout() is:
var myTimeout = setTimeout(functionname(), time);
b. setInterval()
• The setInterval() method is used call a function repeatedly after specified interval.
• The function is called again and again after the specific time interval.
• The clearInterval() can be used to stop the timer.
• The syntax for setInterval() is:
var myInterval= setInterval(functionname(), time);

6. Write a JavaScript that displays all properties of window object. Explain the code.
<html>
<body>
<button onclick="createWindow()">Open a Window</button>
<script>
function createWindow() {
var win = window.open("", "My Window", "width=500,
height=200,top=100,left=100");
// window properties
var isclose = win.closed;
var name = win.name;
// writing in the current document
document.write(isclose + "<br>");
document.write(name + "<br>");
document.write(win.screenY + "<br>");
document.write(win.screenX + "<br>");
// we can access the new window document like this
win.document.write("Hello World!");
}
</script>
</body>
</html>

7. List ways of Protecting your webpage and describe any one of them.
The Ways of protecting Web Page are:
1. Hiding your source code
2. Disabling the right MouseButton
3. Hiding JavaScript
4. Concealing E-mail address.

1.) Hiding your source code


• The source code for your web page—including your JavaScript—is stored in the cache,
the part of computer memory where the browser stores web pages that were requested
by the visitor. A sophisticated visitor can access the cache and thereby gain access to the
web page source code.
• However, you can place obstacles in the way of a potential peeker. First, you can disable
use of the right mouse button on your site so the visitor can't access the View Source
menu option on the context menu. This hides both your HTML code and your JavaScript
from the visitor.
• Nevertheless, the visitor can still use the View menu's Source option to display your
source code. In addition, you can store your JavaScript on your web server instead of
building it into your web page. The browser calls the JavaScript from the web server
when it is needed by your web page. Using this method, the JavaScript isn't visible to
the visitor, even if the visitor
• views the source code for the web page.
• Example for disabling context menu:
<html oncontextmenu="notallowed(); return false">
<body>
<script>
function notallowed() {
alert("Right Click is disabled for this page")
}
</script>
</body>
</html>

8. Write a webpage that displays a form that contains an input for Username and password.
User is prompted to enter the input and password and password becomes value of the
cookie. Write The JavaScript function for storing the cookie. It gets executed when the
password changes.
<html>
<body onload="getCookie()">
<form name>
<label> Username: </label>
<input type="text" id="username" /><br><br>
<label> Password: </label>
<input type="password" id="password" /><br><br>
<input type="button" value="Register" onclick="setCookie()" />
<p id="content"></p>
</body>
<script>
function setCookie() {
document.cookie=
"password=" + document.getElementById("password").value + ";";
getCookie();
}
function getCookie() {
var cookiearray = document.cookie;
cookiearray = cookiearray.split("=");
if (cookiearray[0] == "password")
document.getElementById("content").innerHTML = "Last used
password: " + cookiearray[1];
else
document.getElementById("content").innerHTML = "Cookie not
found"
}
</script>
</html>

9. Write a script for creating following frame structure:

Fruits, Flowers and Cities are links to the webpage fruits.html, flowers.html, cities.html
respectively. When these links are clicked corresponding data appears in "FRAME3".

• index.html
<html>
<frameset rows="10%,90%">
<frame src="frame1.html" />
<frameset cols="50%, 50%">
<frame src="frame2.html" />
<frame name="frame3" />
</frameset>
</frameset>
</html>

• frame1.html
<html>
<body>
<h1>My Website</ </body>
</html>
• frame2.html
<html>
<body>
<li onclick="parent.frame3.location.href='fruits.html'">Fruits</li>
<li onclick="parent.frame3.location.href='flowers.html'">Flowers</li>
<li onclick="parent.frame3.location.href='cities.html'">Cities</li>
</body>
</html>

• fruits.html
<html>
<body>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
</body>
</html>
//Create simiplar html pages for flowers and cities

10. Develop a JavaScript Program to Create Rotating Banner Ads with URL Links.
<html>
<body onload="rotate()">
<a id="link">
<img src="img1.png" id="img" height="100%" width="100%">
</a>
<script>

var pics = [["img1.png", "https://www.instagram.com"],


["img2.png", "https://www.google.com"],
["img3.png", "https://www.snapchat.com"]];
//multidimensional array var count = 0;

function rotate() {
count++; if (count > pics.length - 1) {
count = 0;
}
document.getElementById("img").src = pics[count][0];
document.getElementById("link").href = pics[count][1];
setTimeout("rotate()", 2000)
}
</script>
</body>
</html>
11. Create a slideshow with the group of four images, also simulate the next and previous
transition between slides in your JavaScript
<html>
<body>
<img src="img1.png" id="img" height="50%" width="70%"><br>
<input type="button" value="Previous" onclick="slideshow(-1)">
<input type="button" value="Next" onclick="slideshow(1)">

<script>
var pics = ["img1.png", "img2.png", "img3.png", "img4.png"];
var count = 0;
function slideshow(status) {
count = count + status;
if (count > pics.length - 1) {
count = 0;
}
if (count < 0) {
count = pics.length - 1;
}
document.getElementById("img").src = pics[count];
}
</script>
</body>
</html>
CSS 20M SAMPLE PAPER SOLUTION:
Q.1) Attempt any FOUR. 08 Marks
a) Design the frameset tag for following frame layout:
<!DOCTYPE html>
<html>
<frameset rows="20%,55%,25%">
<frame src="frame1.html" />
<frame src="frame2.html"/>
<frame src="frame3.html"/>
</frameset>
</html>

b) State the method to put message in web browser status bar?


• To display the message in the status bar of the web browser, the “status” property of
the window object is used.
• The status property is used to set the text to be displayed in the browsers status bar.
• However, this property in now not supported in most of the browsers and so is
deprecated.
• Example: window.status = "Some text";

c) Construct regular expression for validating the phone number in following format
only :(nnn)-nnnn-nnnn OR nnn.nnnn.nnnn
<!DOCTYPE html>
<html>
<body>
<script>
var phoneno = prompt("Enter Phone No.");
var pattern1 = /^[(]\d{3,3}[)][-]\d{4,4}[-]\d{4,4}$/;
//format (nnn)-nnnn-nnnn
var pattern2 = /^\d{3,3}[.]\d{4,4}[.]\d{4,4}$/;
//format NNN.NNNN.NNNN
// \d matches any digit, {4,4} specifies minimum and max length,
// ^ specifies match the beginning, $ specifies match the end
var result = pattern1.test(phoneno) || pattern2.test(phoneno)
if(result)
{
alert("Phone No. is Valid")
}
else
alert("Phone No. is Invalid")
</script>
</body>
</html>
Q.2) Attempt any THREE. 12 Marks
a) Write a JavaScript that creates a persistent cookies of Itemnames. Write appropriate
HTML script for the same.
<!DOCTYPE html>
<html>

<body onload="getCookie()">

<form name>
<label> Enter Name: </label>
<input type="text" id="name" /><br><br>
<input type="button" value="Set" onclick="setCookie()" />
<p id="content"></p>

<script>
function setCookie()
{

var expires = (new Date(Date.now()+ 24*60*60*1000)).toUTCString();


//set expire to one day after today in milliseconds.

//or
// var expires = “Sat, 17 Dec 2022 00:00:00 GMT”
// directly specify date and time in UTC format if you don’t want to
use Date constructors.

document.cookie = "itemnames=" + document.getElementById("name").value


+ ";expires="+expires;

getCookie();
}

function getCookie() {

var cookiearray = document.cookie.split(";")[0];

cookiearray = cookiearray.split("=");

if (cookiearray[0] == "itemnames")

document.getElementById("content").innerHTML = "Previous Data:


<br>" + cookiearray[1];

else
document.getElementById("content").innerHTML = "Cookie not found"

}
</script>
</form>
</body>

</html>
b) Write a JavaScript function to check whether a given value is valid IP value or not.
<!DOCTYPE html>
<html>
<body>
<script>
var ipaddr = prompt("Enter IP Address:");
var pattern = /^\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}$/;
// format for ip range 0.0.0.0 to 255.255.255.255
var result = pattern.test(ipaddr)
if(result)
{
alert("IP Address is Valid")
}
else
alert("IP Address is Invalid")
</script>
</body>
</html>

c) Write a JavaScript program to create rollover effect for three images.


<!DOCTYPE html>
<html>
<body>
<img src = "img1.png" id = "i1" height="200" width="200"
onmouseover="roll(this)" onmouseout="reset()">
<img src = "img2.png" id = "i2" height="200" width="200"
onmouseover="roll(this)" onmouseout="reset()">
<img src = "img3.png" id = "i3" height="200" width="200"
onmouseover="roll(this)" onmouseout="reset()">
<script>
function roll(img)
{
img.src="img4.png"
}
function reset()
{
document.getElementById("i1").src="img1.png"
document.getElementById("i2").src="img2.png"
document.getElementById("i3").src="img3.png"
}
</script>
</body>
</html>
d) Write a JavaScript program that create a scrolling text on the status line of a
window.
<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</p>
</body>
</html>
MENUBAR PROGRAM
<!DOCTYPE html>
<html>
<body>
Select the page to navigate:
<select onchange="navigate(this)">
<option value="">---Select---</option> //this is needed
<option value="https://www.google.com">Google</option>
<option value="https://www.yahoo.com">Yahoo</option>
<option value="https://www.bing.com">Bing</option>
</select>
<script>
function navigate(menu) {
window.location = menu.options[menu.selectedIndex].value;
}
</script>
</body>
</html>

You might also like