0% found this document useful (0 votes)
2 views3 pages

SOP4PDF

The document outlines a JavaScript program that calculates the average marks of a student based on six subject scores input by the user. It categorizes the average into grades ranging from A to F based on predefined score ranges. The program displays the average marks and the corresponding grade on a web page.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

SOP4PDF

The document outlines a JavaScript program that calculates the average marks of a student based on six subject scores input by the user. It categorizes the average into grades ranging from A to F based on predefined score ranges. The program displays the average marks and the corresponding grade on a web page.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SOP 9: Create Javascript program which computes the average marks of students.

Accept six
subject marks of student from user. Calculate average marks of student which is used to
determine the corresponding grades.
Range Grade
35 to 60 F
61 to 70 D
71 to 80 C
81 to 90 B
91 to 100 A

CODE:
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Student Grade Calculator</title>
<script>
function calculateGrade() {
// Get values from input fields
let m1 = parseInt([Link]("m1").value);
let m2 = parseInt([Link]("m2").value);
let m3 = parseInt([Link]("m3").value);
let m4 = parseInt([Link]("m4").value);
let m5 = parseInt([Link]("m5").value);
let m6 = parseInt([Link]("m6").value);

// Calculate average
let total = m1 + m2 + m3 + m4 + m5 + m6;
let avg = total / 6;
let grade = "";

// Determine grade
if (avg >= 91 && avg <= 100) {
grade = "A";
} else if (avg >= 81 && avg <= 90) {
grade = "B";
} else if (avg >= 71 && avg <= 80) {
grade = "C";
} else if (avg >= 61 && avg <= 70) {
grade = "D";
} else if (avg >= 35 && avg <= 60) {
grade = "F";
} else {
grade = "Invalid marks entered";
}

// Display result
[Link]("result").innerHTML =
"Average Marks: " + [Link](2) + "<br>Grade: " + grade;
}
</script>
</head>
<body>

<h2>Student Grade Calculator</h2>

<form onsubmit="[Link](); calculateGrade();">


<label>Enter Marks for 6 Subjects:</label><br><br>
Subject 1: <input type="number" id="m1" required><br>
Subject 2: <input type="number" id="m2" required><br>
Subject 3: <input type="number" id="m3" required><br>
Subject 4: <input type="number" id="m4" required><br>
Subject 5: <input type="number" id="m5" required><br>
Subject 6: <input type="number" id="m6" required><br><br>

<button type="submit">Calculate Grade</button>


</form>

<h3 id="result"></h3>

</body>
</html>
OUTPUT:

You might also like