Project 1 - A Notetaking Program

Project Overview

Build a console-based notetaking application where users can:

Functional Requirements

Technical Requirements

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

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:


Next Module: Module 13 - Create Interactive Web Pages