0% found this document useful (0 votes)
108 views2 pages

2nd Assignment Solution cs202

Uploaded by

Talha rashid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views2 pages

2nd Assignment Solution cs202

Uploaded by

Talha rashid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS202 – Front End Development

Assignment No. 02 Solution Due Date: June 24, 2024


Semester: Spring 2024

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grade Calculator</title>
<style>
body{
margin: 700px ;

}
</style>
<script>
function calculateAverage() {
var subject1 = parseFloat(document.getElementById('subject1').value);
var subject2 = parseFloat(document.getElementById('subject2').value);
var subject3 = parseFloat(document.getElementById('subject3').value);
var subject4 = parseFloat(document.getElementById('subject4').value);

if (isNaN(subject1) || isNaN(subject2) || isNaN(subject3) || isNaN(subject4)) {


alert("Please enter valid numeric grades for all subjects.");
return;
}

var total = subject1 + subject2 + subject3 + subject4;


var average = total / 4;

var resultDiv = document.getElementById('result');


resultDiv.innerHTML = ''; // Clear previous result

if (average >= 50) {


resultDiv.innerHTML = 'Congratulations, you passed! <br> Average Grade: ' +
average.toFixed(2) + '%';
} else {
resultDiv.innerHTML = 'Sorry, you failed. <br> Average Grade: ' + average.toFixed(2) + '%';
}

// Add your name and VUID here


resultDiv.innerHTML += '<br> Name: Talha Rashid <br> VUID: BC210408807';
}
</script>

</head>
<body>

<h1>Grade Calculator</h1>

<form name="gradeForm">
Subject 1: <input type="text" id="subject1" required><br><br>
Subject 2: <input type="text" id="subject2" required><br><br>
Subject 3: <input type="text" id="subject3" required><br><br>
Subject 4: <input type="text" id="subject4" required><br><br>
<input type="button" value="Calculate Average" onclick="calculateAverage()">
</form>

<div id="result"></div>

</body>
</html>

Output result

You might also like