Department of Information Technology
Name: Aaditya Mishra
Roll No: A-368 Batch: S4
Subject: Full Stack Java Programming Date: 17/9/2025
EXPERIMENT NO: 08
Aim: To Study & Implement JavaScript.
Theory
JavaScript is a client-side scripting language widely used to add interactivity and
dynamic behavior to web pages. It works inside the browser and allows developers to
perform tasks like form validation, mathematical calculations, manipulating DOM
(Document Object Model), animations, and event handling.
Some important points about JavaScript:
It is lightweight, interpreted, and object-oriented.
It is embedded into HTML using <script> tag.
It can handle both mathematical operations and string manipulations.
JavaScript enhances user experience without needing constant server
communication.
Program 1: Sum of Multiples of 3 and 5 under 1000
Use loops to check numbers between 1 to 1000.
If a number is divisible by 3 or 5, add it to the sum.
Display the final sum using [Link]() or [Link]().
Program 2: Reverse and Product of Digits of a Number
A number can be processed digit by digit using the modulus (%) operator and division.
Reverse → Extract each digit and rebuild the number in reverse order.
Product of digits → Multiply each digit while extracting.
1
Program 3: Form Validation
Form validation ensures that user input is correct, complete, and meaningful before submitting
the form to the server. It prevents errors and enhances data accuracy.
Types of validation:
1. Client-side validation (using JavaScript):
Checks data before submission.
Immediate feedback to the user.
Examples: checking empty fields, email format, password length, numeric values, etc.
2. Server-side validation:
Performed after submission on the server.
More secure, but slower.
Why validation is important?
Prevents incorrect or malicious input.
Improves data accuracy.
Provides better user experience.
2
Problem Statement 1:
Write a JavaScript Program to display sum of 3 & 5 Multiples under 1 Thousand.
<!DOCTYPE html>
<html>
<head>
<title>Sum of Multiples</title>
</head>
<body>
<h2>Sum of Multiples of 3 and 5 (under 1000)</h2>
<form>
<label>Result:</label>
<input type="text" id="result" readonly>
<br><br>
<button type="button" onclick="calculate()">Calculate</button>
</form>
<script>
function sumMultiples(limit) {
let sum = 0;
for (let i = 1; i < limit; i++) {
if (i % 3 === 0 || i % 5 === 0) {
sum += i;
}
}
return sum;
}
function calculate() {
[Link]("result").value = sumMultiples(1000);
}
</script>
</body>
</html>
3
Output:
4
Problem Statement 2:
Write a JavaScript Program to reverse & display product digits of a number.
<!DOCTYPE html>
<html>
<head>
<title>Reverse and Product of Digits</title>
</head>
<body>
<h2>Reverse and Product of Digits</h2>
<form>
<label>Enter a number: </label>
<input type="number" id="num">
<br><br>
<button type="button" onclick="processNumber()">Submit</button>
<br><br>
<label>Reversed Number: </label>
<input type="text" id="reverse" readonly>
<br><br>
<label>Product of Digits: </label>
<input type="text" id="product" readonly>
</form>
<script>
function processNumber() {
let n = parseInt([Link]("num").value);
let original = n;
let rev = 0;
let product = 1;
while (n > 0) {
let digit = n % 10;
rev = rev * 10 + digit;
product *= digit;
n = [Link](n / 10);
}
[Link]("reverse").value = rev;
[Link]("product").value = product;
}
</script>
</body>
</html>
5
Output:
6
Problem Statement 3:
Write a JavaScript Program to validate form (String from user).
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
</head>
<body>
<h2>Registration Form</h2>
<form id="myForm">
<label>Name:</label>
<input type="text" id="name"><br><br>
<label>Email:</label>
<input type="text" id="email"><br><br>
<label>Password:</label>
<input type="password" id="password"><br><br>
<label>Phone:</label>
<input type="text" id="phone"><br><br>
<label>Age:</label>
<input type="number" id="age"><br><br>
<label>Address:</label>
<input type="text" id="address"><br><br>
<button type="button" onclick="validateForm()">Submit</button>
</form>
<script>
function validateForm() {
let name = [Link]("name").[Link]();
let email = [Link]("email").[Link]();
let password = [Link]("password").[Link]();
7
let phone = [Link]("phone").[Link]();
let age = [Link]("age").[Link]();
let address = [Link]("address").[Link]();
if (name === "" || email === "" || password === "" || phone === "" || age === "" ||
address === "") {
alert("All fields are required!");
return false;
}
let emailPattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/;
if () {
alert("Please enter a valid email address!");
return false;
}
let phonePattern = /^[0-9]{10}$/;
if () {
alert("Phone number must be 10 digits!");
return false;
}
if ([Link] < 6) {
alert("Password must be at least 6 characters!");
return false;
}
if (age <= 0) {
alert("Enter a valid age!");
return false;
}
alert("Form submitted successfully!");
return true;
}
</script>
</body>
</html>
8
Output:
Conclusion:
The experiment successfully demonstrated the implementation of JavaScript to solve practical
problems related to web programming, including calculating sums, reversing numbers, and
validating forms. Each program highlighted essential client-side scripting capabilities such as
dynamic calculations, interactivity, and input validation for enhanced user experiences. Through
hands-on coding and output observations, the experiment reinforced key concepts like loop usage,
string manipulation, and data verification. Overall, it provided a foundational understanding of
using JavaScript for reliable and interactive web development.