-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
56 lines (45 loc) · 1.56 KB
/
index.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPA Converter</title>
</head>
<body>
<h1>GPA Converter</h1>
<div>
<label for="inputGPA">Enter GPA:</label>
<input type="number" id="inputGPA" step="0.01" placeholder="e.g. 3.5">
<select id="inputScale">
<option value="4">4.0 Scale</option>
<option value="10">10.0 Scale</option>
</select>
<button onclick="convertGPA()">Convert</button>
</div>
<div>
<h2>Result:</h2>
<p id="outputGPA">Converted GPA will appear here.</p>
</div>
<script>
function convertGPA() {
const gpaValue = parseFloat(document.getElementById('inputGPA').value);
const scaleValue = document.getElementById('inputScale').value;
let convertedGPA;
if (isNaN(gpaValue)) {
alert('Please enter a valid GPA.');
return;
}
if (scaleValue === '4') {
// Convert from 4.0 scale to 10.0 scale
convertedGPA = (gpaValue / 4) * 10;
} else {
// Convert from 10.0 scale to 4.0 scale
convertedGPA = (gpaValue / 10) * 4;
}
// Round the result to two decimal places
convertedGPA = Math.round(convertedGPA * 100) / 100;
document.getElementById('outputGPA').textContent = "Converted GPA: " + convertedGPA;
}
</script>
</body>
</html>