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

1) Write syntax for regular expression constructor function.

ans : var regex = new RegExp(pattern, flags);

2) Enlist and explain the use of any two Intrinsic JavaScript functions.

ans :
1.Use: The parseInt() function is used to parse a string and convert it into an
integer (whole number). It allows you to extract an integer value from the
beginning of a string.

Syntax:

parseInt(string, radix);

string: The string that you want to parse into an integer.


radix (optional): An integer between 2 and 36 that represents the numeral
system to be used (e.g., 10 for decimal, 16 for hexadecimal). If not provided, it is
assumed to be 10.

Example:

var str = "42";


var num = parseInt(str);
console.log(num); // Output: 42

2.Date():

Use: The Date() function is used to work with dates and times in JavaScript. It
allows you to create Date objects, which represent a specific point in time.

Syntax:

To create a new Date object:


javascript
Copy code
var currentDate = new Date();

Example:

var currentDate = new Date();


console.log(currentDate); // Output: Mon Oct 18 2023 13:45:00 GMT-0700

The Date object also provides methods to work with dates, such as getDay(),
getMonth(), getFullYear(), getHours(), and many more, making it a versatile tool
for dealing with date and time-related operations.

These two intrinsic JavaScript functions are essential for working with numbers
and dates in JavaScript, and they are widely used in various web applications and
scripts.
3) Construct regular expression for validating the phone number in
following format only :
ans :

/^\(\d{3}\)-\d{4}-\d{4}$|^\d{3}\.\d{4}\.\d{4}$/

Explanation of the regular expression:

1. '^' and $ denote the start and end of the string, ensuring that the entire string
matches the pattern.
2. '\(, \(, and \\) match the opening and closing parentheses.
3. \d{3} matches three digits.
4. - or \. matches either a hyphen or a period.
5. \d{4} matches four digits.
6. The | character acts as an OR operator, allowing the regular expression to
match either of the provided patterns.
This regular expression will correctly validate phone numbers in the specified
format, either with dashes or periods as separators between groups of digits.

5) List 2 ways of protecting your webpage and describe any one of them.

Content Security Policy (CSP):

HTTPS:

HTTPS is a secure version of the standard HTTP protocol. It uses encryption to


ensure that data transmitted between the user's browser and the web server is
secure and cannot be easily intercepted or manipulated by malicious actors.
HTTPS provides the following benefits:

Data Encryption: HTTPS encrypts the data exchanged between the user's
browser and the web server, making it unreadable to anyone who might
intercept it.

Data Integrity: It ensures that the data transmitted is not tampered with during
transit. If anyone attempts to alter the data, the recipient can detect it.

Authentication: HTTPS uses digital certificates to authenticate the web server,


verifying that users are connecting to a legitimate and trusted website. This
helps prevent man-in-the-middle attacks.

SEO and Trust: Search engines like Google prioritize websites that use HTTPS,
and users are more likely to trust and interact with websites that display the
padlock symbol in the browser's address bar.

To enable HTTPS on your website, you need to obtain an SSL/TLS certificate,


configure your web server to use it, and ensure that all resources (scripts, styles,
images) are loaded via HTTPS. Many web hosting providers offer easy-to-
implement solutions for enabling HTTPS.

Both CSP and HTTPS are crucial components of web security, and implementing
them together provides strong protection for your webpages and users.
6) List all types of menu.

Dropdown Menu:

Context Menu:

Hamburger Menu:

Accordion Menu:

Mega Menu:

Flyout Menu:

Tabbed Menu:

Modal Menu:

Sliding Menu:

Pie Menu:

7) Write a JavaScript that displays all properties of window object. Explain


the code

ans :

10)

ans :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function is_IP(str)
{
regexp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-
9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-
9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^\s*((([0-9A-Fa-f]{1,4}:){7}
([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|
1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:)
{5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-
4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:
[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|
[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]
{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\
d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4})
{0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))
{3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:
((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))
{3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\
d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;

if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}

console.log(is_IP('198.156.23.5'));

console.log(is_IP("172.16.0.1"));

</script>
</head>
<body>

</body>
</html>

12)

ans :
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.banner {
position: relative;
width: 300px;
height: 200px;
overflow: hidden;
}

.ad-link {
display: none;
width: 300px;
height: 100px;

.ad-link img {
width: 100px;
height: 100px;
align-self: center;
}
</style>
</head>

<body>
<div class="banner">
<a href="https://whttps://www.google.com/" class="ad-link">
<img src="banglore.jpeg" alt=" banner 1">
</a>
<a href="https://www.google.com/" class="ad-link">
<img src="mumbai.jpeg" alt=" banner 2">
</a>
<a href="https://www.google.com/" class="ad-link">
<img src="delhi.jpeg" alt=" banner 3">
</a>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const ads = document.querySelectorAll(".ad-link");
let currentAdIndex = 0;

// Function to show the next ad


function showNextAd() {
ads[currentAdIndex].style.display = "none";
currentAdIndex = (currentAdIndex + 1) % ads.length;
ads[currentAdIndex].style.display = "block";
}

// Show the first ad


ads[currentAdIndex].style.display = "block";

// Rotate ads every 5 seconds (adjust the time as needed)


setInterval(showNextAd, 5000);
});
</script>
</body>

</html>

You might also like