Class 12 IT Chapter 3 - Advanced JavaScript Solutions (Maharashtra Board)
विद्यार्थी मित्रांनो, या पोस्टमध्ये आपण Class 12th Information Technology (IT) विषयामधील Chapter 3: Advanced JavaScript मधील सर्व Exercise Questions आणि त्यांचे Solutions पाहणार आहोत. या chapter मध्ये JavaScript च्या advanced concepts चा अभ्यास केला जातो.
Advanced JavaScript Chapter 3 Exercise Solutions
Table of Contents
Q.1) Fill in the blanks
-
_____ script resides on server computer.
Ans: Server Side -
_____ statement is used to jump out of loop.
Ans: Break -
_____ defines logical structure of document.
Ans: DOM (Document Object Model) -
_____ property of window object returns Boolean value indicating whether window is closed or not.
Ans: closed -
_____ event occurs when an element loses its focus.
Ans: On blur
Q.2) State whether given statement is true or false
-
JavaScript is case sensitive language.
Ans: True -
Math.ceil() function is used to return the nearest integer less than or equal to give number.
Ans: False -
MAX_VALUE property of number object returns smallest possible value.
Ans: False -
getDay() method of Date object returns month in number.
Ans: False -
onKeydown event occurs when user moves mouse pointer.
Ans: False
Q.3) Multiple choice questions. Select one correct answer
1) JavaScript is _____ language.
a) Compiled
b) Interpreted
c) Both a and b
d) None of the above
Ans: c) Both a and b
2) Select correct method name of string object _____.
a) charAt()
b) characterAt()
c) valueAt()
d) lengthAt()
Ans: a) charAt()
3) _____ method displays message box with Ok and Cancel button.
a) Confirm()
b) Alert()
c) both a and b
d) None of these
Ans: a) Confirm()
4) We can declare all types of variables using keyword _____.
a) var
b) dim
c) variable
d) declare
Ans: a) var
5) Trace output of following javascript code.
var str="Information Technology";
document.write(str.lastIndexOf("o");
a) 18
b) 19
c) 20
d) 21
Ans: c) 20
Q.4) Multiple choice questions. Select two correct answers
1) Valid two methods of Date object are _____ and _____.
a) setTime()
b) getValidTime()
c) getTime()
d) setValidTime()
Ans: a) setTime(), c) getTime()
2) Properties of document object are _____ and _____.
a) URL
b) title
c) name
d) status
Ans: a) URL, b) title
3) _____ and _____ are event/event handler used with text object in JavaScript.
a) onBlur
b) onMove
c) OnFocus
d) onAction
Ans: a) onBlur, c) onFocus
Q.5) Multiple choice questions. Select three correct answers
1) Select three correct methods of windows object _____
a) write()
b) alert()
c) writeln()
d) close()
e) open()
f) charAt()
Ans: b) alert(), d) close(), e) open()
2) JavaScript features are _____ , _____ and _____.
a) supports event base facilities
b) is platform dependent language
c) case insensitive scripting language
d) provide inbuilt objects
e) can handle date and time effectively
f) required special software to run
Ans: a) supports event base facilities, d) provide inbuilt objects, e) can handle date and time effectively
3) Inbuilt objects in JavaScript are _____, _____ and _____.
a) Time
b) Date
c) Inheritance
d) Array
e) Number
f) function
Ans: b) Date, d) Array, e) Number
Q.6) Explain the following
1) What are similarities and differences between client side scripting and server side scripting.
Ans:
- Server side scripting is used at the backend where the source code is not visible or hidden at the client side (browser).
- Client side scripting is used at the frontend which user can see from the browser.
- Server side scripting is more secure than client side scripting.
- When a server side script is processed it communicates to the server.
- Client-side scripting does not need any server interaction.
- Client side scripting languages: HTML5, JavaScript etc.
- Server side scripting languages: PHP, ASP.net, Ruby, ColdFusion, Python, C# etc.
- Server-side scripting is useful in customizing web pages and implementing dynamic changes.
- Client-side scripts are generally used for validation and minimize server load.
- Server-side scripts require web server software, client side scripts require web browser.
2) Briefly explain features of JavaScript.
Ans:
- JavaScript is lightweight scripting language (doesn't support all OOP features)
- No need of special software to run JavaScript programs
- Object oriented scripting language with event based programming
- Case sensitive language
- Helps browser perform input validation without server access
- Can handle date and time effectively
- Control statement syntax similar to other programming languages
- Ability to create new functions within scripts
- Functions declared using function keyword
- Platform independent language
3) Explain switch......case conditional statement in JavaScript with example.
Ans:
- JavaScript has multiway decision statement known as switch
- Tests value of given expression against list of case values
- When match is found, executes block of statements associated with that case
- No duplicity between cases allowed
- Case values must be same data type as variable in switch
- Default statement is optional
Syntax:
switch(expression) {
case value1:
statement block 1;
break;
case value2:
statement block 2;
break;
..................
case value n:
statement block n;
break;
default:
statement block;
}
Example Program:
<!DOCTYPE html>
<head>
<title> JavaScript Program </title>
</head>
<body>
<h1> Use of Switch case </h1>
<script type="text/javascript">
var day=6;
switch(day) {
case 1: alert("Monday"); break;
case 2: alert("Tuesday"); break;
case 3: alert("Wednesday"); break;
case 4: alert("Thursday"); break;
case 5: alert("Friday"); break;
case 6: alert("Saturday"); break;
case 7: alert("Sunday"); break;
default: alert("Invalid day");
}
</script>
</body>
</html>
Q.7) Write event driven JavaScript program for the following
1) Display Addition, Multiplication, Division and remainder of two numbers
Program:
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
</head>
<body>
<h2>Simple Calculator</h2>
<label for="num1">Number 1: </label>
<input type="number" id="num1">
<br><br>
<label for="num2">Number 2: </label>
<input type="number" id="num2">
<br><br>
<button onclick="calculate()">Calculate</button>
<h3>Results:</h3>
<p id="addition"></p>
<p id="multiplication"></p>
<p id="division"></p>
<p id="remainder"></p>
<script>
function calculate() {
// Get the values entered by the user
var num1 = parseInt(document.getElementById("num1").value);
var num2 = parseInt(document.getElementById("num2").value);
// Perform the calculations
var addition = num1 + num2;
var multiplication = num1 * num2;
var division = num1 / num2;
var remainder = num1 % num2;
// Display the results
document.getElementById("addition").innerHTML = "Addition: " + addition;
document.getElementById("multiplication").innerHTML = "Multiplication: " + multiplication;
document.getElementById("division").innerHTML = "Division: " + division;
document.getElementById("remainder").innerHTML = "Remainder: " + remainder;
}
</script>
</body>
</html>
Output:
2) Display number sequence from 100 to 150
Program:
<!DOCTYPE html>
<html>
<head>
<title>Number Sequence</title>
</head>
<body>
<div id="sequence"></div>
<script ref="text/javascript">
const startNumber = 100;
const endNumber = 150;
let sequence = '';
for (let i = startNumber; i <= endNumber; i++) {
sequence += i + ' ';
}
document.addEventListener('DOMContentLoaded', () => {
const sequenceElement = document.getElementById('sequence');
sequenceElement.textContent = sequence;
});
</script>
</body>
</html>
Output:
3) Find and display factorial of given number
Program:
<!DOCTYPE html>
<html>
<head>
<title>Factorial Calculator</title>
<script>
function calculateFactorial() {
var number = parseInt(document.getElementById("numberInput").value);
var factorial = 1;
for (var i = 2; i <= number; i++) {
factorial *= i;
}
document.getElementById("result").innerHTML = "Factorial: " + factorial;
}
</script>
</head>
<body>
<h1>Factorial Calculator</h1>
<label for="numberInput">Enter a number:</label>
<input type="number" id="numberInput" />
<button onclick="calculateFactorial()">Calculate</button>
<p id="result"></p>
</body>
</html>
Output:
4) Count and display number of vowels in a string
Program:
<!DOCTYPE html>
<html>
<head>
<title>Vowel Counter</title>
<script>
function countVowels() {
var inputString = document.getElementById("inputString").value;
var vowelCount = 0;
var vowels = ['a', 'e', 'i', 'o', 'u'];
for (var i = 0; i < inputString.length; i++) {
var currentChar = inputString.charAt(i).toLowerCase();
if (vowels.includes(currentChar)) {
vowelCount++;
}
}
document.getElementById("result").innerHTML = "Number of vowels: " + vowelCount;
}
</script>
</head>
<body>
<h1>Vowel Counter</h1>
<label for="inputString">Enter a string:</label>
<input type="text" id="inputString" />
<button onclick="countVowels()">Count</button>
<p id="result"></p>
</body>
</html>
Output:
Q.8) Match the following
Column A | Column B |
---|---|
ceil() | Returns next integer greater than or equal to the given number |
floor() | Returns the next integer less than or equal to given number |
write() | Writes HTML expression or JavaScript code to a document |
focus() | Sets focus to current window |
trim() | Remove white spaces from both sides of string |
Ans:
- ceil() → Returns next integer greater than or equal to the given number.
- floor() → Returns the next integer less than or equal to given number.
- write() → Writes HTML expression or JavaScript code to a document.
- focus() → Sets focus to current window.
- trim() → Remove white spaces from both sides of string.
अशा प्रकारे इयत्ता बारावी Information Technology Chapter No 3 - Advanced JavaScript चे Exercise Solutions होते. या Exercise ची PDF Download करण्यासाठी पुढील लिंक वर क्लिक करा.
यापुढील Chapter चे Exercise Solutions क्रमवार पाहण्यासाठी "Next" आणि "Previous" buttons चा उपयोग करावा.
Download PDF: Chapter 3 Advanced JavaScript Exercise Solutions PDF