notation / index.html
omarito03's picture
An offline interactive and simple web application to calculate the final average of subjects. It includes 9 sliders, each representing a subject, allowing the user to set the grade between 10 and 20. Next to each slider is a text field to enter the subject's coefficient, and the product of grade × coefficient is displayed automatically. At the bottom, a large field shows the final average in real time, calculated as the sum of (grades × coefficients) divided by the sum of coefficients. The design is clean and responsive for both mobile and desktop, and there is a Reset button to return all values to their default settings. Optionally, the app can include a feature to calculate the required grades in remaining subjects to achieve a desired final average (e.g., 15/20). - Initial Deployment
ad2482e verified
Raw History Blame Contribute Delete
12 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grade Calculator</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
background: #4f46e5;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 0 2px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
width: 20px;
height: 20px;
background: #4f46e5;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 0 2px rgba(0,0,0,0.2);
}
.grade-display {
min-width: 40px;
text-align: center;
font-weight: 600;
color: #4f46e5;
}
.product-display {
min-width: 60px;
text-align: center;
font-weight: 500;
color: #6b7280;
}
</style>
</head>
<body class="font-inter bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<header class="mb-8 text-center">
<h1 class="text-3xl font-bold text-gray-800 mb-2">Grade Calculator</h1>
<p class="text-gray-600">Calculate your weighted average in real-time</p>
</header>
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
<div class="p-6">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
<div>
<h2 class="text-xl font-semibold text-gray-800 mb-4">Subjects</h2>
<div id="subjects-container" class="space-y-5">
<!-- Subjects will be added here by JavaScript -->
</div>
</div>
<div>
<h2 class="text-xl font-semibold text-gray-800 mb-4">Results</h2>
<div class="bg-indigo-50 rounded-lg p-6">
<div class="flex justify-between items-center mb-4">
<span class="text-gray-700 font-medium">Current Average:</span>
<span id="current-average" class="text-3xl font-bold text-indigo-600">0.00</span>
</div>
<div class="mb-6">
<label for="target-average" class="block text-sm font-medium text-gray-700 mb-1">Target Average</label>
<div class="relative">
<input type="number" id="target-average" min="10" max="20" step="0.1" value="15"
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500">
<span class="absolute right-3 top-2 text-gray-500">/20</span>
</div>
</div>
<div id="required-grades" class="text-sm text-gray-600 hidden">
<p class="font-medium mb-2">To reach your target:</p>
<p>You need an average of <span id="required-average" class="font-semibold">0.00</span> in remaining subjects.</p>
<p class="mt-1">Assuming equal coefficients.</p>
</div>
</div>
</div>
</div>
<div class="flex justify-center space-x-4">
<button id="reset-btn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition flex items-center">
<i data-feather="refresh-cw" class="mr-2 w-4 h-4"></i>
Reset All
</button>
<button id="calculate-btn" class="px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition flex items-center">
<i data-feather="calculator" class="mr-2 w-4 h-4"></i>
Calculate Target
</button>
</div>
</div>
</div>
<footer class="text-center text-gray-500 text-sm">
<p>Offline grade calculator - All calculations happen in your browser</p>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
// Initialize subjects
const subjectsContainer = document.getElementById('subjects-container');
const subjectNames = [
'Mathematics', 'Physics', 'Chemistry',
'Biology', 'History', 'Geography',
'Literature', 'Philosophy', 'Foreign Language'
];
let subjects = [];
// Create subject elements
subjectNames.forEach((name, index) => {
const subjectId = `subject-${index}`;
const subjectHtml = `
<div class="subject-item" data-id="${index}">
<div class="flex justify-between items-center mb-1">
<label for="${subjectId}-name" class="text-sm font-medium text-gray-700">${name}</label>
<span class="grade-display" id="${subjectId}-grade">10.0</span>
</div>
<div class="flex items-center space-x-4">
<input type="range" id="${subjectId}-slider" min="10" max="20" step="0.1" value="10"
class="flex-1 h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
<input type="number" id="${subjectId}-coeff" min="1" max="10" value="1"
class="w-16 px-2 py-1 border border-gray-300 rounded-md text-center">
<span class="product-display" id="${subjectId}-product">10.0</span>
</div>
</div>
`;
subjectsContainer.innerHTML += subjectHtml;
subjects.push({
id: index,
name: name,
grade: 10,
coeff: 1,
product: 10
});
});
// Initialize event listeners
subjectNames.forEach((_, index) => {
const subjectId = `subject-${index}`;
const slider = document.getElementById(`${subjectId}-slider`);
const coeffInput = document.getElementById(`${subjectId}-coeff`);
const gradeDisplay = document.getElementById(`${subjectId}-grade`);
const productDisplay = document.getElementById(`${subjectId}-product`);
slider.addEventListener('input', function() {
const grade = parseFloat(this.value);
subjects[index].grade = grade;
gradeDisplay.textContent = grade.toFixed(1);
updateProduct(index);
updateAverage();
});
coeffInput.addEventListener('input', function() {
const coeff = parseInt(this.value) || 1;
if (coeff < 1) this.value = 1;
if (coeff > 10) this.value = 10;
subjects[index].coeff = coeff;
updateProduct(index);
updateAverage();
});
});
// Reset button
document.getElementById('reset-btn').addEventListener('click', function() {
subjectNames.forEach((_, index) => {
const subjectId = `subject-${index}`;
document.getElementById(`${subjectId}-slider`).value = 10;
document.getElementById(`${subjectId}-coeff`).value = 1;
document.getElementById(`${subjectId}-grade`).textContent = '10.0';
document.getElementById(`${subjectId}-product`).textContent = '10.0';
subjects[index] = {
id: index,
name: subjectNames[index],
grade: 10,
coeff: 1,
product: 10
};
});
updateAverage();
document.getElementById('target-average').value = 15;
document.getElementById('required-grades').classList.add('hidden');
});
// Calculate target button
document.getElementById('calculate-btn').addEventListener('click', function() {
const targetAverage = parseFloat(document.getElementById('target-average').value);
if (isNaN(targetAverage) || targetAverage < 10 || targetAverage > 20) {
alert('Please enter a valid target average between 10 and 20');
return;
}
calculateRequiredGrades(targetAverage);
});
// Helper functions
function updateProduct(index) {
const subject = subjects[index];
subject.product = subject.grade * subject.coeff;
document.getElementById(`subject-${index}-product`).textContent = subject.product.toFixed(1);
}
function updateAverage() {
const totalProducts = subjects.reduce((sum, subject) => sum + subject.product, 0);
const totalCoeffs = subjects.reduce((sum, subject) => sum + subject.coeff, 0);
const average = totalProducts / totalCoeffs;
document.getElementById('current-average').textContent = average.toFixed(2);
}
function calculateRequiredGrades(target) {
const totalProducts = subjects.reduce((sum, subject) => sum + subject.product, 0);
const totalCoeffs = subjects.reduce((sum, subject) => sum + subject.coeff, 0);
const currentAverage = totalProducts / totalCoeffs;
// Assuming remaining subjects have the same coefficients as the average of current ones
const avgCoeff = totalCoeffs > 0 ? totalCoeffs / subjects.length : 1;
const remainingCoeff = 10 - totalCoeffs;
if (remainingCoeff <= 0) {
document.getElementById('required-grades').classList.remove('hidden');
document.getElementById('required-average').textContent = currentAverage.toFixed(2);
return;
}
const requiredTotal = target * (totalCoeffs + remainingCoeff);
const requiredProducts = requiredTotal - totalProducts;
const requiredAverage = requiredProducts / remainingCoeff;
document.getElementById('required-grades').classList.remove('hidden');
document.getElementById('required-average').textContent = requiredAverage.toFixed(2);
}
// Initialize
updateAverage();
});
</script>
<script>feather.replace();</script>
</body>
</html>