Class Average Calculator
Enter student marks separated by commas or new lines. Get class average, highest, lowest score and pass rate instantly.
Advertisement
Advertisement
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=`