0% found this document useful (0 votes)
9 views7 pages

Question Bank Answer For 2 Marks

The document contains a series of questions and answers related to JavaScript, covering intrinsic functions, browser objects, cookies, and regular expressions. It includes explanations of functions like abs(), sqrt(), and innerHTML, as well as descriptions of the location and history objects. Additionally, it provides JavaScript code examples for various functionalities such as opening new windows, validating user input, and managing cookies.

Uploaded by

hj05102006
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)
9 views7 pages

Question Bank Answer For 2 Marks

The document contains a series of questions and answers related to JavaScript, covering intrinsic functions, browser objects, cookies, and regular expressions. It includes explanations of functions like abs(), sqrt(), and innerHTML, as well as descriptions of the location and history objects. Additionally, it provides JavaScript code examples for various functionalities such as opening new windows, validating user input, and managing cookies.

Uploaded by

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

2 MARKS QUESTIONS

✓ Enlist & explain the use of any two Intrinsic JavaScript functions.
✓ b) Describe browser location object..
✓ c) Write attributes of location object.
✓ d) Write attribute and functions of history object
✓ e) Write the use of innerHTML function along with syntax.
✓ f) Write the meaning of sumbols *, + and ? with respect to Quantifiers with suitable example.
✓ g) List and write the meaning of any 4 RegExp flags.
✓ h) List and define types of cookies.
✓ Write syntax to open new window and write meaning of the attributes of opening
✓ new window function.
✓ j) Write the difference between scrollTo( ) and scrollBy( ) functions.
✓ k) Write a Javascript program to display hello world message in the status bar.
✓ l) Write a Java script to design a form to accept values for user ID & password..
4 MARKS QUESTIONS
a) Write a JavaScript program that will open new window when the user will
clicks on the button..
b) Explain efficient Rollover with the help of example
c) Write a Javascript program to select multiple options from checkboxes and
display contents of selected checkboxes.
d) Write a Javascript program to set expiration date of cookie.
e) Write a Javascript program to read contents of cookie.
f) Describe Quantifiers with the help of example.
g) Write a Javascript program to implement slide show of three images.
h) Define timers and Write a Javascript program to implement setInterval( ) and
setTimeout( ) functions
i) Write a javascript program to validate email ID of the user using regular
expression.
j) Develop a JavaScript program to create Rotating Banner Ads.
k) Write a HTML script which displays 2 radio buttons to the users for fruits and
vegetable and 1 option list. When user select fruits radio button option list should
present only fruits names to the user & when user select vegetable radio button
option list should present only vegetable names to the user.
l) Write a javascript program to calculate add, sub, multiplication and division
of two number (input from user). Form should contain two text boxes to input
numbers of four buttons for addition, subtraction, multiplication and division.

1. Enlist & explain the use of any two Intrinsic JavaScript functions.
- Intrinsic function means the building functions that provided by the javascript.
- It means this functions are predefine so , we don’t need to write the code from the scratch.
Question Bank
1. abs() function
- The abs() function returns the absolute value of a number.
- If input number is negative then this function returns the corresponding positive number.
- If the input number is positive or zero then this function returns the number itself.
Syntax :
Math.abs(number);
- Example :
let num = -25; or 20 then it return the 20
let absValue = Math.abs(num); // Returns 25
2. sqrt() Function
- The sqrt() function returns the square root of a number.
Syntax :
Math.sqrt(number);
- Example :
let number = 16;
let squareRoot = Math.sqrt(number); // Returns 4
- This function is used for algebraic and scientif function
3. Date() function
- The Date() function is used to return the current date and time.
- Syntax :
new Date();
Example :
let currentDate = new Date();
console.log(currentDate); // Prints current date and time
4. parseInt() Function
- The parseInt() function converts a string into an integer.
- Syntax:
parseInt(string, radix);
- Example :
let value = parseInt("123"); // Converts "123" to 123

Similar for parse float if you want to exmplain :

2. 3. Describe browser location object..


- The location object contains info about the current URL.
- Location object is a part of window object and it is accessed through “window.location”
- In other word window.location property used to find location and path of the current web page
- Following are the properties / attribute of window location
A) Window.location.pathname : It returns the path name at which the web page is located. It includes folder
and files name
B) Window.location.host name It returns the name of the host on which the web page is running
C) Window.location.protocol: it returns the web page protocol used such as HTTP, file, HTTPS
D) Window. location.assign: It loads the new document
3. Write attribute and functions of history object
- The history object contain the record of all the url visited by the user within a browser window
- The history object is part of window object so it is accessed by window.history
- Property of history
- length : return the no of the urls in list of history

methods of history : -
• back() : used to load previous URL in the history list
• forward() : used to load next URL in the history list
• go() : used to load specific URL in history list.

4. Write the use of innerHTML function along with syntax.


- innerHTML is a property of DOM(Document Object Model) element object ,which is used to get
or set the HTML content of element in javascript.
- It allow programmer to dynamically change/update the content of the webpage without
requiring a page refresh
- Syntax :
element.innerHTML = "New Content"; // To set the content
let content = element.innerHTML; // To get the content
- Example :
<!DOCTYPE html>

<html>
<head>
<title>innerHTML Example</title>
</head>
<body>
<p id="demo">Hello, World!</p>
<button onclick="updateContent()">Click Me</button>

<script>
function updateContent() {
document.getElementById("demo").innerHTML = "Content Updated!";
}
</script>
</body>
</html>

5. Write the meaning of symbols *, + and ? with respect to Quantifiers with suitable example.
- Quantifier is a simple way to specify within a pattern That how many times a particular
character or set of character is allowed to repeat itself.
- There are three non-explicit quantifiers:
Quantifier Meaning

* O or more occurrences

+ 1 or more occurrences

? 0 or 1 occurrence
- Quantifiers apply to the pattern or character immediately to their left.
- Grouping: Use parentheses () to apply quantifiers to a group of characters.
Example :

Pattern Input match


1. Hmj+ Hmj , Hmjj , Hmjjj (Hm not allowed)
2. Hmj* Hmj , Hm, Hmjj
3. Hmj? Hm, Hmj , (Hmjjjjj not allowed)

6. List and write the meaning of any 4 RegExp flags.


- When creating a new regular expression object you can also specify some additional flag to
control how the pattern will be match with other string .
- The flags are appended after the regular expression In literal notation or it can be passed into
the regular expression constructor in the normal notation. Regular expression may have flags
that affect the search pattern
- There are 6 flags in java.
I- when we write this flag search is case insensitive.
g- when we write this flag it will search for all matches.
m-when we write this flag multiline mode is activated.
s- “Dot all” mode, allows to match newline.
u- enables full Unicode support.
y- sticky mod
- Syntax
//Find all matches (global matching) and using case insensitive matching.
var re = / regular expression/gi;

OR
var re = newRegExp (“regular expression”, “gi”);

7. List and define types of cookies


➢ Types of cookie :
✓ Session cookie
✓ Persistent cookie

• Session cookie
- I) Session cookies are temporary cookies that remember users online activities throughout the
session.
- II) i.e It remember the information when a user logged in until logout or when a user close the
web page. when user gets logged out the session cookies get expired.
• Persistent cookie :
- I) A persistent cookie lasts longer because it has an expiration date. It stays saved on your
computer even after you log out or close the browser,until it reaches that expiration date.
- These cookies are stored in a folder in your browser’s installation files.
- You can create, read, or delete these cookies using JavaScript through the document.cookie
command.
8. Write syntax to open new window and write meaning of the attributes of opening

Opening a window :
Open() function :
- This function is used to open a new window from current window.
- It is the part of the window object so it can be accesed by window object only.
- In other word it is the propery of window object so we can access it through the window object
- Syntax
Window.open(URL,name,style);
➢ URL:The URL of the webpage you want to open. This can be a full URL (e.g.,
https://example.com) or a relative path (e.g., /path/to/page). If no URL is provided, a new blank
window will open.
➢ Name: It is used to set the name of new window. It is optional.
➢ Style : Used to specify the style of the new window. The style of the window includes various
parameters such as toolbar, scrollbar, location, height, and width of the window, and so on. This
is an optional parameter.
9. Write the difference between scrollTo( ) and scrollBy( ) functions.

10. Write a Javascript program to display hello world message in the status bar.

<!DOCTYPE html>

<html>
<head>
<title>Status Bar Example</title>
<script>
function showStatusMessage() {
window.status = "Hello World!";
}
</script>
</head>
<body onload="showStatusMessage()">
<h1>Check the status bar for a message</h1>
</body>
</html>
11. Write a Java script to design a form to accept values for user ID & password..

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

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>user id and passowrod</title>
<script>
function check() {
let usernamevalue = document.getElementById("username").value;
let userPassoword = document.getElementById("passoword").value;
if (usernamevalue == "" || userPassoword == "") {
alert("please fill the username and password")
}
else {
alert("thanks " + usernamevalue + " your username and password is
acknowledge")
}
}
</script>
</head>

<body>
<form name="entry">
Enter the name : <input type="text" id="username"><br><br>
Enter the passoword : <input type="text" id="passoword"><br><br>
<input type="button" name="button" value="click" onclick="check()">
</form>
</body>

</html>

You might also like