JavaScript Basics · Course lab · about 150 minutes · 7 tasks · marked out of 100, pass at 60
The fee tracker, in the browser, that remembers
The situation
A small academy in Lahore keeps its fee list on a whiteboard that gets wiped every Friday. Build them a fee tracker that runs in any browser with no server: add a student, see who is clear and who is due, watch the total change live, and find it all still there after the page is closed.
This is the shape of the first thing every front-end job interview asks you to build.
What you'll be able to show
- Hold records in an array of objects and render them with a loop
- Read a form, validate it, and refuse bad input politely
- Derive the totals from the data every time instead of keeping a second copy
- Persist with localStorage and prove it survives a reload
What you need
- A text editor and a browser with its console open (F12)
- Three files: index.html, style.css, app.js
- The lesson 6 starting point
Tasks
-
1The data and the renderIn app.js, start with an array of four student objects (name, feeDue, feePaid). Write render() that clears a list element and adds one row per student showing name, due, paid, and a status word: clear, partial or due.A correct result: Four rows on the page, each with the right status word, produced entirely by render().
-
2The add formA form with name, fee due and fee paid. On submit: prevent the reload, read the values, Number() the amounts, refuse an empty name or a negative amount with a red message under the form, otherwise push a new object and call render().A correct result: A good entry appears immediately; an empty name or -500 shows the message and adds nothing.
-
3Derived totalsShow total due, total paid and total outstanding above the list. Compute them inside render() from the array every time — never keep running totals in separate variables.A correct result: Add a student and the three totals change without any code touching a total directly.
-
4Colour by statusGive each row a class — clear, partial or due — with classList, and style the three in style.css. No inline styles.A correct result: Three visibly different row colours, and no style= attributes in app.js.
-
5Delete, and keep it consistentAdd a delete button to each row that removes that student from the array (filter or splice) and calls render(). Deleting must update the totals too.A correct result: Delete a student and the totals fall by exactly that student's numbers.
-
6Make it rememberSave the array to localStorage as JSON after every change, and load it on startup, falling back to the four starters when nothing is stored. Close the tab, open it again.A correct result: Your added students are still there after the tab is closed and reopened.
-
7Break it, read it, fix itMisspell a variable name on purpose, open the console, read the error and fix it. Then paste one sentence into your notes: what the error said and which line it named.A correct result: One error message recorded with its line number.
What to hand in
The three files in a folder (zipped or a link), a screenshot after a reload showing your added students still present, and the one-sentence error note.
How it is marked
| Criterion | Points |
|---|---|
| Render loop produces every row from the array | 15 |
| Form validates and refuses bad input with a visible message | 20 |
| Totals are derived in render(), not kept separately | 15 |
| Status classes styled in CSS, no inline styles | 10 |
| Delete keeps the list and totals consistent | 15 |
| localStorage save and load survive a reload | 20 |
| The error note names the line | 5 |
| Total · pass at 60 | 100 |
صورتحال
لاہور کی ایک چھوٹی academy اپنی فیس کی فہرست ایک whiteboard پر رکھتی ہے جو ہر جمعے کو مٹ جاتا ہے۔ ان کے لیے ایک فیس tracker بنائیں جو بغیر server کے کسی بھی browser میں چلے: student شامل کریں، دیکھیں کون clear ہے اور کس پر بقایا ہے، total کو live بدلتے دیکھیں، اور صفحہ بند کرنے کے بعد سب کچھ وہیں موجود پائیں۔
یہی وہ شکل ہے جو ہر front-end job interview میں سب سے پہلے بنانے کو کہی جاتی ہے۔
آپ کیا دکھا سکیں گے
- records کو objects کی array میں رکھنا اور loop سے render کرنا
- form پڑھنا، validate کرنا، اور غلط input کو شائستگی سے رد کرنا
- ہر بار totals کو data سے نکالنا، دوسری copy رکھنے کے بجائے
- localStorage سے محفوظ رکھنا اور ثابت کرنا کہ reload کے بعد بھی رہتا ہے
آپ کو کیا چاہیے
- ایک text editor اور console کھلا ہوا browser (F12)
- تین files: index.html، style.css، app.js
- سبق 6 کا ابتدائی نقطہ
کام
-
1data اور renderapp.js میں چار student objects کی array سے شروع کریں (name، feeDue، feePaid)۔ render() لکھیں جو ایک list element خالی کرے اور ہر student کی ایک قطار شامل کرے جس میں نام، بقایا، ادا شدہ، اور ایک status لفظ ہو: clear، partial یا due۔درست نتیجہ: صفحے پر چار قطاریں، ہر ایک صحیح status لفظ کے ساتھ، پوری طرح render() سے بنی ہوئی۔
-
2add formنام، فیس واجب اور فیس ادا کے ساتھ ایک form۔ submit پر: reload روکیں، values پڑھیں، رقموں کو Number() کریں، خالی نام یا منفی رقم کو form کے نیچے سرخ پیغام سے رد کریں، ورنہ نیا object push کریں اور render() call کریں۔درست نتیجہ: اچھی entry فوراً نظر آئے؛ خالی نام یا -500 پیغام دکھائے اور کچھ شامل نہ ہو۔
-
3نکالے ہوئے totalslist کے اوپر کل واجب، کل ادا شدہ اور کل بقایا دکھائیں۔ انہیں ہر بار render() کے اندر array سے نکالیں — کبھی الگ variables میں چلتے ہوئے totals نہ رکھیں۔درست نتیجہ: student شامل کریں اور تینوں totals بدل جائیں بغیر کسی code کے total کو براہِ راست چھوئے۔
-
4status کے حساب سے رنگہر قطار کو classList سے ایک class دیں — clear، partial یا due — اور تینوں کو style.css میں style کریں۔ کوئی inline styles نہیں۔درست نتیجہ: تین واضح طور پر مختلف قطاروں کے رنگ، اور app.js میں کوئی style= attribute نہیں۔
-
5delete، اور یکسانیتہر قطار میں ایک delete button شامل کریں جو اس student کو array سے ہٹائے (filter یا splice) اور render() call کرے۔ delete پر totals بھی update ہوں۔درست نتیجہ: student delete کریں اور totals بالکل اسی student کے نمبروں سے کم ہوں۔
-
6اسے یاد رکھنے والا بنائیںہر تبدیلی کے بعد array کو JSON کے طور پر localStorage میں save کریں، اور شروع ہونے پر load کریں، کچھ محفوظ نہ ہونے پر چاروں ابتدائی students پر واپس جاتے ہوئے۔ tab بند کریں، دوبارہ کھولیں۔درست نتیجہ: tab بند کر کے دوبارہ کھولنے کے بعد آپ کے شامل کیے ہوئے students وہیں موجود ہوں۔
-
7توڑیں، پڑھیں، ٹھیک کریںجان بوجھ کر ایک variable کا نام غلط لکھیں، console کھولیں، error پڑھیں اور ٹھیک کریں۔ پھر اپنے notes میں ایک جملہ لکھیں: error نے کیا کہا اور کون سی line بتائی۔درست نتیجہ: ایک error message اپنے line number کے ساتھ ریکارڈ شدہ۔
کیا جمع کروانا ہے
تینوں files ایک folder میں (zip یا link)، reload کے بعد کا screenshot جس میں آپ کے شامل کیے ہوئے students موجود ہوں، اور error کا ایک جملے کا note۔
نمبر کیسے ملیں گے
| معیار | نمبر |
|---|---|
| render loop ہر قطار array سے بناتا ہے | 15 |
| form validate کرتا ہے اور غلط input کو نظر آنے والے پیغام سے رد کرتا ہے | 20 |
| totals render() میں نکالے جاتے ہیں، الگ نہیں رکھے جاتے | 15 |
| status classes CSS میں style ہیں، inline styles نہیں | 10 |
| delete list اور totals کو یکساں رکھتا ہے | 15 |
| localStorage کا save اور load reload کے بعد قائم رہتا ہے | 20 |
| error note میں line کا نام ہے | 5 |
| کل · پاس 60 | 100 |
Hand in your lab
Create a free BvLogic ID to hand in your lab, get it marked, and have it on your certificate.
Create your BvLogic IDAlready have one? Sign in and this course will be added to it.