Question Bank Answer For 2 Marks
Question Bank Answer For 2 Marks
✓ 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
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.
<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 :
OR
var re = newRegExp (“regular expression”, “gi”);
• 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>