Project 1 - A Notetaking Program
Project Overview
Build a console-based notetaking application where users can:
- Add notes with titles
- View all notes
- Remove notes by index
- Clear all notes
Functional Requirements
- Add new notes with title and content
- Display all notes with formatting
- Delete specific notes by index
- Clear all notes with confirmation
- Validate input before adding
Technical Requirements
- Use classes to create a
NoteAppclass - Store notes in an array
- Implement methods for CRUD operations
- Use functional programming concepts where appropriate
- Include error handling
Project Structure
NoteApp/
├── noteapp.js
├── README.md
└── tests.js
Implementation Steps
Step 1: Create the NoteApp Class
class NoteApp {
constructor() {
this.notes = [];
}
addNote(title, content) {
if (!title || !content) {
throw new Error("Title and content are required");
}
this.notes.push({
id: Date.now(),
title: title,
content: content,
createdAt: new Date()
});
return true;
}
removeNote(index) {
if (index < 0 || index >= this.notes.length) {
throw new Error("Invalid note index");
}
this.notes.splice(index, 1);
return true;
}
getAllNotes() {
return this.notes;
}
clearAllNotes() {
this.notes = [];
}
displayNotes() {
if (this.notes.length === 0) {
console.log("No notes found");
return;
}
this.notes.forEach((note, index) => {
console.log(`\n[${index}] ${note.title}`);
console.log(`${note.content}`);
console.log(`Created: ${note.createdAt}`);
});
}
}
Step 2: Test the Application
let app = new NoteApp();
// Add notes
app.addNote("Shopping", "Milk, Bread, Eggs");
app.addNote("Meeting", "Prepare presentation");
// Display notes
app.displayNotes();
// Remove a note
app.removeNote(0);
// Display again
app.displayNotes();
Expected Output
[0] Shopping
Milk, Bread, Eggs
Created: [timestamp]
[1] Meeting
Prepare presentation
Created: [timestamp]
Challenges to Avoid
- Data Persistence: Notes are lost on refresh (addressed in web version)
- Input Validation: Always validate before adding
- Index Management: Be careful with array indices after deletion
- Memory Leaks: Clear references when deleting
Extensions
Extension 1: Search Notes
searchNotes(keyword) {
return this.notes.filter(note =>
note.title.includes(keyword) ||
note.content.includes(keyword)
);
}
Extension 2: Update Notes
updateNote(index, title, content) {
if (index < 0 || index >= this.notes.length) {
throw new Error("Invalid index");
}
this.notes[index].title = title;
this.notes[index].content = content;
}
Extension 3: Note Categories
addNote(title, content, category = "General") {
this.notes.push({
title, content, category,
createdAt: new Date()
});
}
getNotesByCategory(category) {
return this.notes.filter(n => n.category === category);
}
Learning Outcomes
After completing this project, you should be able to:
- ✅ Design and implement a class structure
- ✅ Use arrays to manage data
- ✅ Implement CRUD operations
- ✅ Validate user input
- ✅ Create a functional console application
Next Module: Module 13 - Create Interactive Web Pages