-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (29 loc) · 1.24 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function calculateAverage() {
// Sınav sayısını al
const examCount = parseInt(document.getElementById('examCount').value);
// Sınav notlarını al
const grades = [];
for (let i = 1; i <= examCount; i++) {
const grade = parseInt(document.getElementById(`grade${i}`).value);
grades.push(grade);
}
// Ortalamayı hesapla
const sum = grades.reduce((acc, grade) => acc + grade, 0);
const average = sum / examCount;
// Sonucu ekrana yazdır
const resultElement = document.getElementById('result');
resultElement.textContent = `Ortalama: ${average.toFixed(2)}`;
}
// Dinamik olarak sınav notu giriş alanları eklemek için
document.getElementById('examCount').addEventListener('change', function () {
const examCount = parseInt(this.value);
const examGradesContainer = document.getElementById('examGrades');
examGradesContainer.innerHTML = ''; // Önceki not alanlarını temizle
for (let i = 1; i <= examCount; i++) {
const input = document.createElement('input');
input.type = 'number';
input.placeholder = `Sınav ${i} Notu`;
input.id = `grade${i}`;
examGradesContainer.appendChild(input);
}
});