Question Bank
Question Bank
Question Bank
(22519)
Question Bank
4 4 4
2 marks
High-level language
1. JavaScript is a object-based scripting language.
2. Giving the user more control over the browser.
3. It Handling dates and time.
4. It Detecting the user's browser and OS,
5. It is light weighted.
6. Client – Side Technology
7. JavaScript is a scripting language and it is not java.
8. JavaScript is interpreter based scripting language.
9. JavaScript is case sensitive.
10. JavaScript is object based language as it provides predefined objects.
11. Every statement in javascript must be terminated with semicolon (;).
12. Most of the javascript control statements syntax is same as syntax of
control statements in C language.
13. An important part of JavaScript is the ability to create new functions
within scripts.
2. Write a javascript program to check whether entered number is prime or not.
if (isPrime) {
document.write (number + " is a prime number.");
} else {
Document.write (number + " is not a prime number.");
}
3. List & explain datatypes in JavaScript
<html>
<body>
<script>
var person = {
firstname:"John",
lastname:"Doe",
age:50,
eyecolor:"blue"
};
delete person.eyecolor; //delete person eyecolor
document.write("After delete "+ person.firstname +" "+ person.lastname +" "
+person.age +" "+ person.eyecolor);
</script>
</body>
</html>
7. State the ways to display the output in JavaScript.
There are several ways to display output in JavaScript, depending on the context in
which you are working. Here are some common methods for displaying output:
1. **`console.log()`**: This is the most commonly used method for displaying output in JavaScript. It
logs messages and values to the browser's developer console. It's primarily used for debugging and
development.
```javascript
console.log("Hello, World!");
```
2. **`alert()`**: This method displays a dialog box with a message and an OK button. It's often used
for simple user notifications.
```javascript
alert("Hello, World!");
```
3. **`document.write()`**: This method writes text directly to the HTML document. It's typically used
for simple output but can overwrite the entire document if used after the document has finished
loading.
```javascript
document.write("Hello, World!");
```
4. **`innerHTML` property**: You can use the `innerHTML` property to set or change the content of
an HTML element. This is useful for updating the content of specific elements on a webpage.
```javascript
document.getElementById("outputElement").innerHTML = "Hello, World!";
```
5. **`console.info()`, `console.warn()`, `console.error()`**: These are variants of `console.log()` that
allow you to log information, warnings, and errors, respectively. They help categorize the messages in
the console.
```javascript
console.info("Informational message");
console.warn("Warning message");
console.error("Error message");
```
6. **`prompt()`**: This method displays a dialog box that prompts the user to input text. It can be
used to get input from the user.
```javascript
const userInput = prompt("Enter your name:");
console.log("User entered: " + userInput);
```
7. **`confirm()`**: This method displays a dialog box with a message and OK/Cancel buttons. It's
used to get user confirmation for an action.
```javascript
const confirmed = confirm("Are you sure you want to proceed?");
if (confirmed) {
// Proceed with the action
} else {
// Cancel the action
}
```
8. **Browser Developer Tools**: In addition to JavaScript's built-in methods, you can use browser
developer tools to inspect and log output directly from your code. This is especially useful for
debugging.
8. List the logical operators in JavaScript with description.
Logical AND (&&):
Description: Returns true if both operands are true.
Example: true && true returns true, while true && false returns false.
Logical OR (||):
Description: Returns true if at least one of the operands is true.
Example: true || false returns true, and false || false returns false.
Logical NOT (!):
Description: Returns the opposite boolean value of the operand. If the operand is true, it returns
false, and if the operand is false, it returns true.
Example: !true returns false, and !false returns true.
Logical XOR (Exclusive OR) (^):
Description: Returns true if exactly one of the operands is true, but not both.
Example: true ^ false returns true, while true ^ true and false ^ false return false.
9. Write JavaScript to create a object "student" with properties roll number name, branch,
year. Delete branch property and display remaining properties of student object.
// Create a student object
const student = {
rollNumber: 12345,
name: "John Doe",
branch: "Computer Science",
year: 2023
};
// Display the original student object
console.log("Original Student Object:");
console.log(student);
// Delete the 'branch' property
delete student.branch;
// Display the modified student object with the 'branch' property removed
console.log("Student Object after Deleting 'branch' Property:");
console.log(student);
Sample paper
10. State the use of dot syntax in JavaScript with the help of suitable example.
It is the most common way to interact with object properties. Here's how the dot syntax is used with
a suitable example:
const person = {
firstName: "John",
lastName: "Doe",
age: 30,
greet: function () {
console.log(`Hello, my name is ${this.firstName} ${this.lastName}, and I am ${this.age} years old.`);
}
};
console.log(person.firstName); console.log(person.age);
person.greet();
11. List and explain Logical operators in JavaScript
12. Give syntax of and explain the use of “with” statement/clause in JavaScript using suitable
example.
The with statement in JavaScript is used to simplify the process of accessing multiple properties or
methods of an object. It allows you to work with the properties and methods of an object without
explicitly referencing the object's name each time. However, it's important to note that the with
statement is considered bad practice and is not recommended for use in modern JavaScript due to
potential issues and performance concerns. It can lead to ambiguities and make code harder to
maintain.
with (object) {
// Code that uses properties or methods of the object
}
Example:
const person = {
firstName: "John",
lastName: "Doe",
age: 30
};
with (person) {
console.log(firstName);
console.log(lastName);
console.log(age);
}
console.log(person.firstName);
console.log(person.lastName);
console.log(person.age);
13. State use of getters and setters
14. Write a JavaScript that displays first 20 even numbers on the document window.
<!DOCTYPE html>
<html>
<head>
<title>Display Even Numbers</title>
</head>
<body>
<h1>First 20 Even Numbers:</h1>
<p id="evenNumbers"></p>
<script>
let evenNumbersText = '';
for (let i = 2; i <= 40; i += 2) {
evenNumbersText += i + ', ';
}
document.getElementById('evenNumbers').textContent = evenNumbersText;
</script>
</body>
</html>
4 marks
15. Write a javascript program to validate user accounts for multiple set of user ID and
password (using swith case statement).
const validUserAccounts = {
user1: 'password1',
user2: 'password2',
user3: 'password3',
};
Sample Output:
“1 is odd"
"2 is even”
for (let i = 1; i <= 15; i++) {
if (i % 2 === 0) {
console.log(`${i} is even`);
} else {
console.log(`${i} is odd`);
}
}
18.
<html>
<head>
<title>Even Numbers</title>
</head>
<body>
<script>
var i = 0;
while (i < 20) {
document.write(i + "<br>");
i += 2;
}
</script>
</body>
</html>
Sample paper
19. Write a JavaScript program which compute, the average marks of the following students
Then, this average is used to determine the corresponding grade.
Student Marks
Name
Amit 70
Sumit 78
Abhishek 71
<script>
// Create an array of students
var students = [
{ name: "Amit", marks: 70 },
{ name: "Sumit", marks: 78 },
{ name: "Abhishek", marks: 71 },
];
21. Explain Object creation in JavaScript using 'new' keyword with adding properties and
methods with example.
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function selection()
{
var x ="You selected: ";
with(document.forms.myform)
{
if(a.checked == true)
{
x+= a.value+ " ";
}
if(b.checked == true)
{
x+= b.value+ " ";
}
if(o.checked == true)
{
x+= o.value+ " ";
}
if(p.checked == true)
{
x+= p.value+ " ";
}
if(g.checked == true)
{
x+= g.value+ " ";
}
document.write(x);
}
}
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Fruits: <br>
<input type="checkbox" name="a" value="Apple">Apple
<input type="checkbox" name="b" value="Banana">Banana
<input type="checkbox" name="o" value="Orange">Orange
<input type="checkbox" name="p" value="Pear">Pear
<input type="checkbox" name="g" value="Grapes">Grapes
<input type="reset" value="Show" onclick="selection()">
</form>
</body>
</html>
</form>
</body>
</html>
22. Write a program to print sum of even numbers between 1 to 100 using for loop
// Initialize the sum variable to 0.
let sum = 0;
// Iterate from 2 to 100, adding each even number to the sum variable.
for (let i = 2; i <= 100; i += 2) {
sum += i;
}
// Print the sum of even numbers.
console.log(`The sum of even numbers between 1 to 100 is: ${sum}`);
23. Write a javascript to checks whether a passed string is palindrome or not. 6 Marks.
<script language="javascript" type="text/javascript">
function isPalindrome(str) {
// Remove non-alphanumeric characters and convert the string to lowercase
str = str.replace(/[^A-Za-z0-9]/g, '').toLowerCase();
return str === str.split('').reverse().join('');
}
// Test the function with some examples
const input1 = "racecar";
const input2 = "hello";
document.write(`"${input1}" is a palindrome: ${isPalindrome(input1)}`);
document.write(`"${input2}" is a palindrome: ${isPalindrome(input2)}`);
</script>
Unit – II Array, Function and String (Marks :14)
2 4 8
2marks
1. Write a JavaScript that initializes an array called “Fruits” with names of five fruits. The script
then displays the array in a message box.
// Initialize an array called "Fruits" with names of five fruits
const Fruits = ["Apple", "Banana", "Orange", "Grapes", "Strawberry"];
Sample paper
16. Describe all the tokens of the following statements :
i. document.bgColor
ii. document.write()
17. State the use of following methods.
i. charCodeAt()
ii. fromCharCode()
Sample paper
41. Write a JavaScript function to count the number of vowels in a given string
42. Write a JavaScript that find and displays number of duplicate values in an array.
43. Write a function that prompts the user for a color and uses what they select to set the
background color of the new webpage opened .
44. Develop JavaScript to convert the given character to Unicode and vice versa.
6 marks
45. Write a javascript function to generate Fibonacci series till user defined limit.
46. Develop javascript to convert the given character to unicode and vice-versa.
2 4 4
2 marks
6 marks
7. Write HTML code to design a form that displays two textboxes for accepting two
numbers, one textbox for accepting result and two buttons as ADDITION and
SUBTRACTION. Write proper JavaScript such that when the user clicks on any one
of the button, respective operation will be performed on two numbers and result will
be displayed in result textbox.
8. Write a javascript to create option list containing list of images and then display
images in new window as per selection.
9. Explain how to evaluate Radiobutton in JavaScript with suitable example
10. Write a HTML script which displays 2 radiobuttons 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.
11. Describe how to evaluate checkbox selection. Explain with suitable example.
12. Write a HTML script which displays 2 radio buttons to the users for fruits and vegetables
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
13. Write HTML script that will display dropdown list containing options such as Red, Green,
Blue & Yellow. Write a JavaScript program such that when the user selects any options. It
will change the background colour of webpage.
Sample paper
14. Write HTML Script that displays textboxes for accepting Name, middlename, Surname of the user
and a Submit button. Write proper JavaScript such that when the user clicks on submit button i) all
texboxes must get disabled and change the color to “RED”. and with respective labels. 3 ii) Constructs
the mailID as .@msbte.com and displays mail ID as message. (Ex. If user enters Rajni as name and
Pathak as surname mailID will be constructed as rajni.pathak@msbte.com)
UNIT-IV Cookies and Browser Data (Marks: 08)
2 2 4
2 marks
Sample paper
2. Write a JavaScript that identifies a running browser.
3. State and explain what is a session cookie?
4 marks
4. Design a webpage that displays a form that contains an input for user name and
password. User is prompted to enter the input user name and password and password
become value of the cookies. Write the javascript function for storing the cookies.
5. Write a javascript program to create read, update and delete cookies.
6. Explain how to create and read Persistent Cookies in JavaScript with example.
7. Write HTML code to design a form that displays two buttons START and STOP. Write
a JavaScript code such that when user clicks on START button, real time digital clock
will be displayed on screen. When user clicks on STOP button, clock will stop
displaying time. (Use Timer methods)
Sample paper
8. Write a JavaScript that displays all properties of window object. Explain the code .
9. Write the syntax of and explain use of following methods of JavaScript Timing Event. a.
setTimeout() b. setInterval()
10. Generate college Admission form using html form tag .
11. Write a JavaScript that creates a persistent cookies of Itemnames. Write appropriate HTML
script for the same.
6 marks
12. Describe, how to read cookie value and write a cookie value. Explain with example
13. Write a webpage that displays a form that contains an input for username & password.
User is prompted to enter the input & password & password becomes the value of the
cookie.
14. Write a JavaScript function for storing the cookie. It gets executed when the password
changes.
15. Write a webpage that diplays 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.
2 6 6
4 marks
1. Describe regular expression. Explain search () method used in regular expression with
suitable example.
2. Explain text rollover with suitable example.
3. Write a Java script that displays textboxes for accepting name & email ID & a submit
button. Write Java script code such that when the user clicks on submit button (1) Name
Validation (2) Email ID validation
4. Write a script for creating following frame structure
FRAME 1
FRAME 2 FRAME 3
• FRUITS
• FLOWERS
• CITIES
Sample paper
12. Construct regular expression for validating the phone number in following format only : (nnn)-
nnnn-nnnn OR nnn.nnnn.nnnn
13. Design the frameset tag for following frame layout :
FRAME1
FRAME2
FRAME3
4 marks
Sample paper
14. State what is regular expression. Explain its meaning with the help of a suitable example.
15. Write a webpage that accepts Username and adharcard as input texts. When the user enters
adhaarcard number ,the JavaScript validates card number and diplays whether card number is valid or
not. (Assume valid adhaar card format to be nnnn.nnnn.nnnn or nnnn-nnnn-nnnn).
16 .Write a JavaScript function to check whether a given value is valid IP value or not
17.Write a JavaScript program to create rollover effect for three images.
18.Write a javascript program to validate email ID of the user using regular expression.
19.Describe regular expression. Explain search () method used in regular expression with
suitable example.
20.Explain test() and exec() method of Regular Expression object with example.
21.Explain open() method of window object with syntax and example.
22.Write a javascript program to design HTML page with books information in tabular
format, use rollovers to display the discount information
23.Explain text and image rollover with suitable example,
6 marks
Chapter 1 & Chapter 2 are linked to the webpage Ch1 HTML & Ch2.html respectively. When
user click on these links corresponding data appears in FRAME3.
Sample paper
25. Write a javascript to open a new window and the new window is having two frames. One
frame containing button as “click here !”, and after clicking this button an image should open
in the second frame of that child window.
26.When user clicks MUSIC button,music.html webpage will appear in Frame 3. When user
clicks DANCE button,dance.html webpage will appear in Frame 4.Write a script for creating
following frame structure Frame I contains three buttons SPORT, MUSIC and DANCE that
will perform following action: When user clicks SPORT button, sport.html webpage will
FRAME 1
appear in Frame 2.
</html>
2 4 6
1. Create a slideshow with the group of three images, also simulate next and previous
transition between slides in your Java script
2. Write a Javascript to create a pull – down menu with three options [Google,
MSBTE, Yahoo] once the user will select one of the options then user will be
redirected to that site.
3. Describe frameworks of JavaScript & its application.
4. Describe how to link banner advertisement to URL with example.
5. Develop a JavaScript program to create Rotating Banner Ads.
6. Write HTML script that will display dropdown list containing options such as
Red, Green, Blue and Yellow. Write a JavaScript program such that when the
user selects any options. It will change the background colour of webpage.
7. Write a JavaScript for the folding tree menu.
2 marks
Sample paper
16. List ways of protecting your web page and describe any one of them.
17. Create a slideshow with the group of three images, also simulate next and previous
transition between slides in your Java Script.
18.Write a Java script to modify the status bar using on MouseOver and on MouseOut with
links. When the user moves his mouse over the link, it will display “MSBTE” in the status
bar. When the user moves his mouse away from the link the status bar will display nothing.
6marks
Sample paper
24. Write HTML Script that displays dropdownlist containing options NewDelhi, Mumbai,
Bangalore. Write proper JavaScript such that when the user selects any options
corresponding description of about 20 words and image of the city appear in table which
appears below on the same page.
25. Create a slideshow with the group of four images, also simulate the next and previous
transition between slides in your JavaScript.