|
| 1 | +/* Create a system that processes student data, calculates grades, filters results, and generates reports. It should handle real-world logic like grade calculations, filtering by criteria, and data transformations. |
| 2 | +
|
| 3 | +What to Build: |
| 4 | +An array of student objects, where each student has: name, marks (array of subject scores), attendance percentage |
| 5 | +Functions that: |
| 6 | +Calculate average marks and assign grades (A/B/C/D based on ranges) |
| 7 | +Filter students by criteria (e.g., "show only students with > 75 average") |
| 8 | +Find top performer and lowest scorer |
| 9 | +Check eligibility (average > 40 AND attendance > 75%) |
| 10 | +Loops to iterate through data and transform it |
| 11 | +Conditionals to apply grading rules (use switch for grade assignment or if/else for eligibility) |
| 12 | +Generate a summary report showing: total students, pass count, fail count, average class score |
| 13 | +How to Approach It: |
| 14 | +Start with data structure — Create realistic student objects with nested arrays (marks per subject) |
| 15 | +Build utility functions — Each function should do ONE thing (calculate average, assign grade, filter students) |
| 16 | +Use loops strategically — .map() mindset (though not required): transform data from one form to another |
| 17 | +Apply game logic — Use conditionals creatively (e.g., bonus points if attendance > 90%) |
| 18 | +Combine everything — Chain functions and loops to build the final report |
| 19 | +Challenge Twist (Optional): |
| 20 | +Add a pass/fail rule: If marks < 40, fail regardless of attendance |
| 21 | +Add a merit scholarship checker: Show students eligible for scholarship (average > 80 AND attendance 100) |
| 22 | +Export data to a formatted string report using template literals |
| 23 | +This project forces them to design with objects, organize logic with functions, and process data with loops — all core pillars. |
| 24 | + */ |
| 25 | +// Sample student data |
| 26 | +const students = [ |
| 27 | + { name: "Ram", marks: [85, 90, 78], attendance: 92 }, |
| 28 | + { name: "Shyam", marks: [70, 75, 80], attendance: 85 }, |
| 29 | + { name: "Hari", marks: [60, 65, 58], attendance: 80 }, |
| 30 | + { name: "Gita", marks: [30, 35, 28], attendance: 70 }, |
| 31 | + { name: "Sita", marks: [95, 98, 92], attendance: 100 } |
| 32 | +]; |
| 33 | + |
| 34 | +function avg(student){ |
| 35 | + let totalMark=0 |
| 36 | + for (let index = 0; index < student.marks.length; index++) { |
| 37 | + totalMark+=student.marks[index] |
| 38 | + } |
| 39 | + return totalMark / student.marks.length; |
| 40 | +} |
| 41 | + |
| 42 | +const avgmarks =[] |
| 43 | +for(let i=0;i<students.length;i++){ |
| 44 | + avgmarks.push(avg(students[i])) |
| 45 | + |
| 46 | +} |
| 47 | +console.log(avgmarks) |
| 48 | +let highestMark = avgmarks[0] |
| 49 | +for(let i=0;i<avgmarks.length;i++){ |
| 50 | + if(avgmarks[i]>highestMark){ |
| 51 | + highestMark = avgmarks[i] |
| 52 | + } |
| 53 | +} |
| 54 | +console.log("Highest Mark:", highestMark) |
| 55 | + let lowestMark = avgmarks[0] |
| 56 | + |
| 57 | +for(let i=0;i<avgmarks.length;i++){ |
| 58 | + if(avgmarks[i]<lowestMark){ |
| 59 | + lowestMark = avgmarks[i] |
| 60 | + } |
| 61 | +} |
| 62 | +console.log("Lowest Mark:", lowestMark) |
| 63 | + |
| 64 | + const accArray=[] |
| 65 | +for (let index = 0; index < avgmarks.length; index++) { |
| 66 | + let highestMark = avgmarks[0] |
| 67 | + for(let j=0;j<avgmarks.length;j++){ |
| 68 | + if(avgmarks[j]>highestMark){ |
| 69 | + highestMark = avgmarks[j] |
| 70 | + } |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | + accArray.push(highestMark) |
| 75 | + const index = avgmarks.indexOf(highestMark) |
| 76 | + avgmarks[index] = -1 |
| 77 | +console.log(avgmarks) |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +} |
| 82 | +console.log("Sorted Marks:", accArray) |
| 83 | + |
| 84 | + |
0 commit comments