<!DOCTYPE html> <html> <head> <title>GAP Calculator</title> <style> /* CSS styles */ body { font-family: Arial, sans-serif; background-color: white; margin: 0; padding: 20px; } h1 { color: #333333; } table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } table th, table td { padding: 10px; border: 1px solid #cccccc; text-align: left; } table th { background-color: #967BB6; font-weight: bold; color: white; } .add-row-btn, .remove-row-btn, .reset-btn, .calculate-btn { padding: 5px 10px; background-color: #967BB6; border: none; color: white; cursor: pointer; transition: background-color 0.3s ease; border-radius: 50px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } .add-row-btn, .reset-btn, .calculate-btn { background-color: #967BB6; padding: 10px 16px; border-radius: 7px; text-decoration: none; color: white; display: inline-block; font-size: 14px; margin: 4px 2px; transition-duration: 0.6s; cursor: pointer; } .add-row-btn:hover, .remove-row-btn:hover, .reset-btn:hover, .calculate-btn:hover { background-color: #7D55C7; color: white; } .error { color: #ff0000; font-size: 14px; } .instruction { margin-bottom: 20px; } .gpa-result { margin-top: 13px; font-weight: bold; } @media (max-width: 480px) { table { display: block; overflow-x: auto; white-space: nowrap; } table thead, table tbody, table tr, table th, table td { display: block; } table thead tr { position: absolute; top: -9999px; left: -9999px; } table tr { margin-bottom: 15px; } table td { border: none; position: relative; padding-left: 50%; text-align: left; } table td:before { position: absolute; top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; content: attr(data-label); font-weight: bold; } .add-row-btn, .remove-row-btn, .reset-btn, .calculate-btn { width: 100%; margin-bottom: 10px; } .course, .credit, .Grade { width: 100%; padding: 5px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }} </style> <script> // JavaScript functions function addRow() { var table = document.getElementById("gap-table"); var row = table.insertRow(-1); var courseCell = row.insertCell(0); var gradeCell = row.insertCell(1); var creditCell = row.insertCell(2); var actionCell = row.insertCell(3); courseCell.innerHTML = '<input type="text" class="course" required>'; gradeCell.innerHTML = ` <select class="grade" required> <option value="">Select Grade</option> <option value="4.00">A+</option> <option value="4.00">A</option> <option value="3.70">A-</option> <option value="3.30">B+</option> <option value="3.00">B</option> <option value="2.70">B-</option> <option value="2.30">C+</option> <option value="2.00">C</option> <option value="1.70">C-</option> <option value="1.30">D+</option> <option value="1.00">D</option> <option value="0.70">D-</option> <option value="0">F</option> <option value="0">FIN</option> <option value="0">WF</option> </select> `; creditCell.innerHTML = '<input type="number" class="credit" min="0" required>'; actionCell.innerHTML = '<button class="remove-row-btn" onclick="removeRow(this)">Remove</button>'; } function removeRow(button) { var row = button.parentNode.parentNode; row.parentNode.removeChild(row); } function calculateGPA() { var courses = document.getElementsByClassName("course"); var grades = document.getElementsByClassName("grade"); var credits = document.getElementsByClassName("credit"); var totalCredits = 0; var totalGradePoints = 0; for (var i = 0; i < courses.length; i++) { if (courses[i].value.trim() === "" || grades[i].value === "" || credits[i].value === "") { showError("Please fill in all fields."); return; } var credit = parseInt(credits[i].value); var grade = parseInt(grades[i].value); totalCredits += credit; totalGradePoints += credit * grade; } if (totalCredits === 0) { showError("Please add at least one course."); return; } var gpa = totalGradePoints / totalCredits; var resultText = "Your GPA is: " + gpa.toFixed(2); var creditsText = "Total Credits: " + totalCredits; showResult(resultText, creditsText); } function resetCalculator() { var table = document.getElementById("gap-table"); var rowCount = table.rows.length; for (var i = rowCount - 1; i > 0; i--) { table.deleteRow(i); } clearError(); clearResult(); } function showError(message) { var errorDiv = document.getElementById("error-msg"); errorDiv.innerHTML = message; } function clearError() { var errorDiv = document.getElementById("error-msg"); errorDiv.innerHTML = ""; } function showResult(result, credits) { var resultDiv = document.getElementById("gpa-result"); resultDiv.innerHTML = result + "<br>" + credits; } function clearResult() { var resultDiv = document.getElementById("gpa-result"); resultDiv.innerHTML = ""; } </script> </head> <body> <h1>Semester GPA Calculator</h1> <p>Note: This calculator only helps you forecaste a semester's GPA. Please consult with your advisor for proper calculation of your GPA.</p> <div class="instruction"> <p>Instructions:</p> <ul> <li>Fill in the course information in each row.</li> <li>To add a new row, click the "Add Row" button.</li> <li>To remove a row, click the "Remove" button for that row.</li> <li>Ensure that no rows are left blank before calculating the GPA.</li> </ul> </div> <table id="gap-table"> <thead> <tr> <th>Course</th> <th>Grade</th> <th>Credit Hours</th> <th>Action</th> </tr> </thead> <tbody> <tr> <td data-label="Course"><input type="text" class="course" required></td> <td data-label="Grade"> <select class="grade" required> <option value="">Select Grade</option> <option value="4.00">A+</option> <option value="4.00">A</option> <option value="3.70">A-</option> <option value="3.30">B+</option> <option value="3.00">B</option> <option value="2.70">B-</option> <option value="2.30">C+</option> <option value="2.00">C</option> <option value="1.70">C-</option> <option value="1.30">D+</option> <option value="1.00">D</option> <option value="0.70">D-</option> <option value="0">F</option> <option value="0">FIN</option> <option value="0">WF</option> </select> </td> <td data-label="Credit"><input type="number" class="credit" min="0" required></td> <td data-label="Action"><button class="remove-row-btn" onclick="removeRow(this)">Remove</button></td> </tr> </tbody> </table> <button class="add-row-btn" onclick="addRow()">Add Row</button> <button onclick="calculateGPA()" class="calculate-btn">Calculate GPA</button> <button class="reset-btn" onclick="resetCalculator()">Reset</button> <div id="error-msg" class="error"></div> <div class="gpa-result" id="gpa-result"></div> </body>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>