BCA Student Stories & UpdatesLive
JavaScript Functions: Declarations, Arrow Syntax, Parameters & Scope
Functions are the fundamental building blocks of modular programming. Instead of duplicating lines of logic, functions encapsulate actions into reusable, testable subroutines that accept inputs, process data, and return results.
Day 25 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
JavaScript Functions: Declarations, Arrow Syntax, Parameters & Scope — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
Functions are the fundamental building blocks of modular programming. Instead of duplicating lines of logic, functions encapsulate actions into reusable, testable subroutines that accept inputs, process data, and return results.
"Think of a function like an automated espresso coffee machine: you insert water and beans (inputs/arguments), it grinds and brews (process), and it hands you a cup of coffee (return value)."
👨🏫3. Teacher Demonstration Code
See how both traditional declarations and modern arrow functions perform calculations and return values cleanly.
<!DOCTYPE html>
<html>
<body>
<script>
// 1. Traditional Function Declaration
function calculateSGPA(gradePoints, totalCredits) {
if (totalCredits === 0) return 0;
return (gradePoints / totalCredits).toFixed(2);
}
// 2. Modern ES6 Arrow Function
const isPassingGrade = (score) => score >= 40;
// 3. Arrow Function with Implicit Return
const calculatePercentage = (marks, maxMarks) => (marks / maxMarks) * 100;
console.log("SGPA:", calculateSGPA(82, 10)); // "8.20"
console.log("Is 45 Passing?", isPassingGrade(45)); // true
console.log("Percentage:", calculatePercentage(420, 500)); // 84
</script>
</body>
</html>2. Hands-On Practical Lab: Follow Instructions in VS Code
Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.
Day 25 Practical Task Test Studio
Define an arrow function calculatePercentage accepting (obtained, total) and returning (obtained / total) * 100.
Write a function checkExamStatus(pct) that returns "PASS" if pct >= 40, else returns "FAIL".
Spot the Bug: Missing Return in Multi-line Arrow Function
Tap or click on the exact line below that contains the error:
Click any code lineconst getDiscount = (price) => { const discount = price * 0.15; // Missing: return discount;}; const finalDiscount = getDiscount(1000);console.log("Discount:", finalDiscount); // Prints: undefined!Senior Developer Forensic Analysis:
When an arrow function uses curly braces {}, it requires an explicit return statement. Without return, JavaScript functions return undefined by default.
📝Independent Practice: Assignment
📄 marksheet-util.htmlUniversal BCA Marksheet Utility Module
- •Create day-25/index.html with modular JavaScript functions.
- •Write calculatePercentage(marks, total) and getLetterGrade(percentage).
- •Write formatStudentReport(name, percentage, letterGrade) returning a clean multiline string.
- •Test the functions with 3 student profiles and log reports to console.
Open Visual Studio Code on your PC (code .), create marksheet-util.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BCA Day 25 - Universal Marksheet Utility Module</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', Tahoma, sans-serif;
background: #0b1120;
color: white;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.card {
background: #1e293b;
border: 1px solid #334155;
border-radius: 16px;
padding: 28px;
max-width: 520px;
width: 100%;
}
h1 { font-size: 20px; color: #38bdf8; margin-bottom: 12px; }
pre {
background: #0f172a;
padding: 16px;
border-radius: 8px;
font-size: 13px;
color: #a5b4fc;
white-space: pre-wrap;
line-height: 1.6;
}
</style>
</head>
<body>
<div class="card">
<h1>BCA Marksheet Generator Functions</h1>
<pre id="output">Computing student reports...</pre>
</div>
<script>
// 1. Percentage calculator function
const calculatePercentage = (marks, total) => ((marks / total) * 100).toFixed(1);
// 2. Letter grade evaluator function
function getLetterGrade(percentage) {
if (percentage >= 80) return "A+ (Distinction)";
if (percentage >= 65) return "A (First Division)";
if (percentage >= 50) return "B (Second Division)";
if (percentage >= 40) return "C (Pass)";
return "F (Needs Improvement)";
}
// 3. Multiline report builder function
function formatStudentReport(name, marks, total) {
const pct = calculatePercentage(marks, total);
const grade = getLetterGrade(pct);
return `🎓 Student Report: ${name}
• Score: ${marks}/${total}
• Percentage: ${pct}%
• Final Grade: ${grade}`;
}
// Test with 3 students
const report1 = formatStudentReport("Raja Roy", 420, 500);
const report2 = formatStudentReport("Pankaj Sharma", 380, 500);
const report3 = formatStudentReport("Gauri Patel", 460, 500);
const fullOutput = [report1, report2, report3].join("\n\n--------------------------------\n\n");
console.log(fullOutput);
document.getElementById("output").textContent = fullOutput;
</script>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
What is the return value of a JavaScript function that does NOT contain a return statement?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 25 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-25/ for today so you don't overwrite previous days.main.You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 25 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 24: Loops & Iteration: for, while, and for...of Statements first.
Complete Day 24 First