Created
December 24, 2018 03:58
-
-
Save tscholl2/e636fe80f98621f26946388e1b5f0dd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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