Javascript
SHORT ANSWER QUESTIONS-5 MARKS
1. 2082 Q.No. 11 Write JavaScript code
to input any three numbers and find the smallest number among them.
<html>
<head>
<title> Smallest
among of three numbers</title>
</head>
<body>
<script>
var a =
parseInt(prompt("Enter 1st number"));
var b =
parseInt(prompt("Enter 2nd number"));
var c =
parseInt(prompt("Enter 3rd number"));
if(a<b&&a<c)
{
alert(a+ "is smallest");
}
else
if(b<a&&b<c)
{
alert(b+ "is smallest");
}
else
{
alert(c+ "is smallest");
}
</script>
</body>
</html>
2.2081 GIE Set A Q.No. 11 Write a
JavaScript Code snippet, along with HTML, that displays the multiplication
table of a entered number.
<html>
<head>
<title>Multiplication Table</title>
</head>
<body>
<script>
var a = parseInt(prompt("Enter a number"));
for (var i = 1; i <= 10; i++) {
document.write(a + " × " + i + " = " + (a * i) +
"<br>");
}
</script>
</body>
</html>
3.2081 GIE Set B Q.No. 11 Write a
program in JavaScript to find largest number among three numbers.
<html>
<head>
<title>Greatest Among Three Numbers</title>
</head>
<body>
<script>
var a = parseInt(prompt("Enter first number"));
var b = parseInt(prompt("Enter second number"));
var c = parseInt(prompt("Enter third number"));
if (a >b && a > c) {
document.write("Greatest number is: " + a);
} else if (b > a && b > c) {
document.write("Greatest number is: " + b);
} else {
document.write("Greatest number is: " + c);
}
</script>
</body>
</html>
4. 2081 Q.No. 11 Write a JavaScript
function that checks if a number is even or odd and print the result.
<html>
<head>
<title>Odd Even using Function</title>
</head>
<body>
<script>
function check(n)
{
var r = n % 2;
if (r == 0)
{
document.write(n + " is
even");
}
else
{
document.write(n + " is
odd");
}
}
check(n);
</script>
</body>
</html>
5. 2080 GIE Set A Q.No. 11 Write a
program to find the largest number among three numbers in JavaScript.
<html>
<head>
<title>Greatest Among Three Numbers</title>
</head>
<body>
<script>
var a = parseInt(prompt("Enter first number"));
var b = parseInt(prompt("Enter second number"));
var c = parseInt(prompt("Enter third number"));
if (a > b && a > c) {
document.write("Greatest number is: " + a);
} else if (b > a && b > c) {
document.write("Greatest number is: " + b);
} else {
document.write("Greatest number is: " + c);
}
</script>
</body>
</html>
6. 2080 GIE Set B Q.No. 11 How do you
add an event handler in JavaScript? Give an example.
We can add an event handler in
JavaScript in two main ways:
1.
Using HTML Attribute (Inline Event Handler)
<button
onclick="displayMessage()">Click Me</button>
<script>
function displayMessage() {
alert("Button clicked!");
}
</script>
2.
Using JavaScript's addEventListener()
<button id="btn">Click
Me</button>
<script>
document.getElementById("btn").addEventListener("click",
function() {
alert("Button clicked using addEventListener!");
});
</script>
7. 2080 Q.No. 110R Write a JavaScript
code to calculate the factorial of a given number.
<html>
<head>
<title>Factorial of a Number</title>
</head>
<body>
<script>
var n = parseInt(prompt("Enter a number"));
var fact = 1;
for (var i = 1; i <= n; i++) {
fact = fact * i;
}
document.write("Factorial of " + n + " is: " +
fact);
</script>
</body>
</html>
8. 2079 GIE Set A Q.No. 11 Write a
function to enter two numbers and find sum of two numbers in JavaScript.
<html>
<head>
<title>Sum of Two Numbers</title>
</head>
<body>
<script>
function add(a, b) {
return a + b;
}
var n1 = parseInt(prompt("Enter first number"));
var n2 = parseInt(prompt("Enter second number"));
var result = add(n1, n2);
document.write("Sum = " + result);
</script>
</body>
</html>
9. 2079 Set A Q.No. 11 Write a program
to find the factorial of any given number using Javascript.
<html>
<head>
<title>Factorial of a Number</title>
</head>
<body>
<script>
var n = parseInt(prompt("Enter a number"));
var fact = 1;
fact = fact * i;
}
document.write("Factorial of " + n + " is: " +
fact);
</script>
</body>
</html>
10. Write short notes on Internet
technology.
Internet technology refers to the set of
techniques, protocols, and systems that enable computers and other digital
devices to connect, communicate, and exchange data over a global network called
the Internet. It allows users to access information, services, and resources
from anywhere in the world.
The technology is based on standard
communication protocols like TCP/IP, which ensure reliable data transfer
between devices. Through Internet technology, various applications such as
email, web browsing, online banking, e-learning, and social networking are
possible. It has revolutionized communication, education, business, and
entertainment by making information easily accessible and shareable globally.
11. Differentiate between server-side
and client-side scripting.
Client-Side Scripting | Server-Side Scripting |
Client side scripting is used at the front end which users can see from the browser | Server side scripting is used at the backend where the source code is not viewable or hidden at the client side browser |
Its main function is to provide the requested output to end user. | Its primary function is to manipulate and provides access to the respective database as per the request |
It runs on the user’s computer . | It runs on the webserver |
Client side scripting does not need any server interaction | When a server side script is processed it communicates to the server |
It usually depends on the browser and its version. | In this any server side technology can be used and it does not depend on the client |
It is useful in minimizing the load on the server | It is useful in customizing the web pages and implementing dynamic changes in the website. |
It is not secured compared to the server side as a client side script is visible to the users | It is more secure than client side scripting as scripts are usually hidden from the client end. |
The client side scripting langauges involves languages such as html css and javascript | Server side language involves programming such as PHP, ASP.NET, Python, C#, JSP etc. |
12. Explain different data types used in
JavaScript.
Data Types Used in JavaScript
1.
Primitive (Simple) Data Types
These store single values
a) Number
Used to store numeric values (integer or
decimal).
var age = 20;
b) String
Used to store text (characters, words,
sentences).
var name = "Ram";
c) Boolean
Stores either true or false.
var isPass = true;
d) Undefined
A variable declared but not assigned any
value.
var x;
e) Null
Represents empty or no value.
var data = null;
2. Composite (Reference) Data Types
These can store multiple values.
a) Object
Collection of key–value pairs.
var student = {name: "Sita",
age: 18};
b) Array
List of multiple values in a single
variable.
var marks = [80, 75, 90];
c) Function
A block of code that performs a specific
task.
function add(a, b) {
return a + b;
}
LONG
ANSWER QUESTIONS-8 MARKS
13. 2079 GIE Set B Q.No. 15 What are the
uses of Java Script in web page development?
JavaScript is a client-side scripting
language widely used to make web pages dynamic, interactive, and responsive.
Its main uses in web development are:
1. Client-Side Validation
·
JavaScript
can validate user input in forms before sending it to the server.
·
Example:
Checking if all required fields are filled, or if an email address is in the
correct format.
·
Reduces
server load and improves user experience.
2. Dynamic Content
·
JavaScript
allows web pages to change content without reloading the page.
·
Example:
Updating text, images, or tables dynamically based on user actions.
3. Event Handling
·
Responds
to user actions such as clicks, mouse movements, keyboard input, etc.
·
Example:
Displaying a popup when a button is clicked or changing the color of a button
on hover.
4. Interactive Effects
·
Adds
interactive features to web pages such as image sliders, tabs, dropdown menus,
and animations.
·
Enhances
the overall look and feel of the website.
5. Browser Control
·
JavaScript
can control browser actions like opening new windows, printing a page, or
redirecting to another page.
·
Example:
`window.open()`, `window.location.href`.
6. Cookies and Storage
·
JavaScript
can store data in cookies or local storage for remembering user preferences or
session information.
·
Example:
Keeping a user logged in or remembering selected language on the website.
7. Communication with Server (AJAX)
·
JavaScript
can request data from the server without reloading the page, using AJAX.
·
Example:
Loading new messages in a chat app or updating search results dynamically.
8. Formatted Output and Calculations
·
JavaScript
can perform calculations and display results instantly on the page.
·
Example:
Online calculators, dynamic pricing in e-commerce websites.
14. What is Object-based programming?
Explain different JavaScript objects.
Object-based programming is a programming
approach in which data and functions are grouped together into objects. Unlike
full object-oriented programming (OOP), object-based programming does not
support inheritance but allows encapsulation and use of objects to structure
programs.
In JavaScript, object-based programming
allows developers to create objects that store data (properties) and behavior
(methods), making web applications more organized and easier to manage.
Different
JavaScript Objects
JavaScript provides several built-in
objects that can be used in web development:
1. String Object
·
Represents
text and provides properties and methods for text manipulation.
·
Example:
var name = new String("Ram");
document.write(name.length);
2. Number Object
·
Represents
numeric values and provides methods for numeric operations.
·
Example:
var num = new Number(100);
document.write(num.toFixed(2));
3. Boolean Object
·
Represents
logical values: true or false.
·
Example:
var flag = new Boolean(true);
document.write(flag); // true
4. Array Object
·
Stores
multiple values in a single variable as a list.
·
Example:
var marks = [80, 75, 90];
document.write(marks[0]);
5. Date Object
·
Represents
date and time, with methods to get and set date/time values.
·
Example:
var today = new Date();
document.write(today.getFullYear()); //
2025
6. Math Object
·
Provides
mathematical constants and functions like `Math.PI`, `Math.sqrt()`,
`Math.random()`.
·
Example:
document.write(Math.sqrt(16)); // 4
7. Object Object
·
The
base object from which all other objects are derived. You can create custom
objects.
·
Example:
var person = {name: "Sita",
age: 18};
document.write(person.name); // Sita