Season 2 ka chautha project: ek Notes App — note likho, save karo, delete karo, aur search box se turant dhundo. Page band karke dobara kholo, notes wahi milenge, kyunki hum unhe localStorage me save karte hain.
<textarea> aur <input> ko ek jaisa style karnaunshift se sabse naya note upar jodnalocalStorage + JSON.stringify / JSON.parse — notes browser me savetoLowerCase() aur includes() se filterrender() pattern — data badlo, phir list dobara banaoHar step me "Editor me daalo" dabao — ya best: khud type karo, haath se likha code yaad rehta hai. ✍️
#search input, uske neeche #text textarea (naya note) aur #add button.#list khaali div hai — saare notes JavaScript yahan dalega.placeholder — khaali box me halka sa hint text. <div class="app">
<h1>My Notes 📝</h1>
<input id="search" placeholder="Search notes...">
<textarea id="text" placeholder="Naya note likho..."></textarea>
<button id="add">Save note</button>
<div id="list"></div>
</div>
display: grid + place-items: center.width: 300px ka — phone par bhi fit.body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #0f172a;
font-family: sans-serif;
}
.app {
width: 300px;
padding: 24px;
background: #1e293b;
border-radius: 24px;
}
input, textarea { ... } — comma se dono ko ek saath style.box-sizing: border-box + width: 100% — padding aur border bhi 100% ke andar rahe.resize: none — textarea ka kona kheench kar bada nahi hoga.h1 { margin: 0 0 12px; color: #fff; font-size: 22px; }
input, textarea {
box-sizing: border-box;
width: 100%;
margin-bottom: 8px;
padding: 9px 12px;
border: 2px solid #334155;
border-radius: 10px;
background: #0f172a;
color: #fff;
font: 14px sans-serif;
}
textarea { height: 56px; resize: none; }
#list par max-height + overflow: auto — zyada notes ho jaye to list scroll hogi, card badhega nahi.#add {
width: 100%;
padding: 10px 0;
border: 0;
border-radius: 10px;
background: #6366f1;
color: #fff;
cursor: pointer;
}
#list { max-height: 140px; margin-top: 12px; overflow: auto; }
display: flex + space-between — text left, ✕ button right.border-left pink — card ke baayein ek rang ki patti..note {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
padding: 10px 12px;
border-left: 4px solid #ec4899;
border-radius: 8px;
background: #334155;
color: #e2e8f0;
font-size: 14px;
}
.note p { margin: 0; }
.note button {
border: 0;
background: none;
color: #94a3b8;
cursor: pointer;
}
notes ek array hai (har note ek text). Pehli baar kuch saved nahi hota, isliye || [].try / catch — kuch jagah localStorage band hota hai, tab bhi app chalega.const search = document.querySelector('#search');
const text = document.querySelector('#text');
const addBtn = document.querySelector('#add');
const list = document.querySelector('#list');
let notes = [];
try {
notes = JSON.parse(localStorage.getItem('notes')) || [];
} catch (e) {}
JSON.stringify se array ko text banaya.function save() {
try {
localStorage.setItem('notes', JSON.stringify(notes));
} catch (e) {}
}
q = search box ka text (chhote akshar me). Har note ko bhi chhote akshar me karke includes(q) se match.return — us note ko skip. Khaali search me sab match hote hain.textContent se note daala — user ka likha HTML kabhi chalega nahi (safe).splice(i, 1) se array se hatao, phir save() aur render().function render() {
const q = search.value.toLowerCase();
list.innerHTML = '';
notes.forEach((n, i) => {
if (!n.toLowerCase().includes(q)) return;
const card = document.createElement('div');
card.className = 'note';
card.innerHTML = '<p></p><button>✕</button>';
card.querySelector('p').textContent = n;
card.querySelector('button').onclick = () => {
notes.splice(i, 1);
save();
render();
};
list.append(card);
});
}
trim() se space hatao, khaali ho to kuch nahi.unshift — array ke shuru me jodta hai, isliye naya note upar aata hai.search par input event — har akshar likhte hi list filter. Aakhri render() page khulte hi saved notes dikhata hai.addBtn.addEventListener('click', () => {
const v = text.value.trim();
if (!v) return;
notes.unshift(v);
text.value = '';
save();
render();
});
search.addEventListener('input', render);
render();
Naya day aate hi reel aayegi — @codeyantra follow karo 🔔