7-bank-project/3-data/assignment.md
By completing this assignment, you will practice essential software development skills that professional developers use daily. You'll learn to organize code for maintainability, reduce duplication through abstraction, and document your work for future developers (including yourself!).
Clean, well-documented code is crucial for real-world web development projects where multiple developers collaborate and codebases evolve over time.
Your banking app's app.js file has grown significantly with login, registration, and dashboard functionality. It's time to refactor this code using professional development practices to improve readability, maintainability, and reduce duplication.
Transform your current app.js code by implementing these three core refactoring techniques:
Task: Create a configuration section at the top of your file with reusable constants.
Implementation guidance:
Example structure:
// Configuration constants
const API_BASE_URL = 'http://localhost:5000/api';
const ROUTES = {
LOGIN: '/login',
DASHBOARD: '/dashboard'
};
Task: Build a reusable sendRequest() function that eliminates duplicate code between createAccount() and getAccount().
Requirements:
Function signature guidance:
async function sendRequest(endpoint, method = 'GET', data = null) {
// Your implementation here
}
Task: Document your code with clear, helpful comments that explain the "why" behind your logic.
Documentation standards:
Example documentation style:
/**
* Authenticates user and redirects to dashboard
* @param {Event} event - Form submission event
* @returns {Promise<void>} - Resolves when login process completes
*/
async function login(event) {
// Prevent default form submission to handle with JavaScript
event.preventDefault();
// Your implementation...
}
Your refactored code should demonstrate these professional development practices:
sendRequest() functionsendRequest() function created but may not handle all edge casesAfter refactoring, ensure your banking app still functions correctly:
sendRequest() function works for both account creation and retrievalSubmit your refactored app.js file with:
Bonus Challenge: Create a simple code documentation file (CODE_STRUCTURE.md) that explains your app's architecture and how the different functions work together.
This assignment mirrors the type of code maintenance that professional developers perform regularly. In industry settings:
The skills you're practicing here - extracting constants, eliminating duplication, and writing clear documentation - are fundamental to professional software development.