Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<head>
<script type="text/javascript">
const grades = [
"A+",
"A",
"A-",
"B+",
"B",
"B-",
"C+",
"C",
"C-",
"D+",
"D",
"D-",
"F"
];
function scale(max, min) {
const arr = [];
for (let i = 0; i < 13; i++) {
arr.push((i * (max - min)) / 13 + min);
}
return arr;
}
function run(e) {
e && e.preventDefault();
const max = parseInt(document.getElementById("max").value, 10);
const min = parseInt(document.getElementById("min").value, 10);
const arr = scale(max, min);
document.getElementById("output").innerHTML = "";
const ul = document.createElement("ul");
for (let i = 0; i < 13; i++) {
const li = document.createElement("li");
li.innerHTML = `<span>${grades[i]}</span><span>=</span><span>${
arr[i]
}</span>`;
ul.appendChild(li);
}
document.getElementById("output").appendChild(ul);
}
window.onload = function() {
document.getElementsByTagName("form").item(0).onsubmit = run;
};
</script>
<style>
#output {
text-align: center;
}
</style>
</head>
<html>
<body>
<form style="display:flex;flex-direction:columns;">
<label> A+ <input id="max" type="number" placeholder="90" /> </label>
<label> F <input id="min" type="number" placeholder="50" /> </label>
<button type="submit">submit</button>
</form>
<div id="output"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment