Class Average Calculator

Enter student marks separated by commas or new lines. Get class average, highest, lowest score and pass rate instantly.

Advertisement
Advertisement

Related tools

function calculate() { const raw = document.getElementById('marks-input').value; const passmark = +document.getElementById('passmark').value || 50; const marks = raw.split(/[\n,]+/).map(m => parseFloat(m.trim())).filter(m => !isNaN(m) && m >= 0); if (marks.length === 0) { alert('Please enter at least one valid mark.'); return; } const avg = marks.reduce((a,b)=>a+b,0) / marks.length; const sorted = [...marks].sort((a,b)=>a-b); const passed = marks.filter(m=>m>=passmark).length; const failed = marks.length - passed; const passRate = (passed/marks.length*100).toFixed(1); const median = sorted.length%2===0 ? (sorted[sorted.length/2-1]+sorted[sorted.length/2])/2 : sorted[Math.floor(sorted.length/2)]; document.getElementById('result').style.display='block'; document.getElementById('result').innerHTML=`
${avg.toFixed(1)}
Class average
${sorted[sorted.length-1]}
Highest mark
${sorted[0]}
Lowest mark
${marks.length}
Total students
${passed} passed
${passRate}% pass rate
${failed} failed
Below ${passmark}
`; } document.addEventListener('DOMContentLoaded', () => { const related = TOOLS.filter(t => t.category==='teacher' && t.slug!=='class-average-calculator').slice(0,4); document.getElementById('related-grid').innerHTML = related.map(buildToolCard).join(''); });