-
Notifications
You must be signed in to change notification settings - Fork 1
/
if_else.js
35 lines (28 loc) · 951 Bytes
/
if_else.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
// Function to determine grade based on marks
function determineGrade(marks) {
let grade;
if (marks >= 70) {
grade = 'A';
} else if (marks >= 60) {
grade = 'B';
} else if (marks >= 50) {
grade = 'C';
} else if (marks >= 40) {
grade = 'D';
} else {
grade = 'F';
}
return grade;
}
// Event listener for the form submission
const gradeForm = document.getElementById('gradeForm');
// Event listener for the form submission
gradeForm.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
const marks = Number(document.getElementById('marks').value); // Get marks from input
const grade = determineGrade(marks); // Determine grade
// Save the result div to a variable
const resultDiv = document.getElementById('result');
// Display the result
resultDiv.innerText = `Your grade is: ${grade}`;
});